Skip to content

Commit

Permalink
Skip unnecessary string allocs from frquently executed code paths.
Browse files Browse the repository at this point in the history
Differential Revision: D2540814

fb-gh-sync-id: 045d012b52a6bc89d409bcc028532da1760c5775
  • Loading branch information
kmagiera authored and facebook-github-bot-6 committed Oct 14, 2015
1 parent aae9f02 commit 10a9b94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public int getModuleId() {

public int getMethodId(Method method) {
final Integer id = mMethodsToIds.get(method);
Assertions.assertNotNull(id, "Unknown method: " + method.getName());
if (id == null) {
Assertions.assertUnreachable("Unknown method: " + method.getName());
}
return id.intValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
*/
public class SoftAssertions {

/**
* Throw {@link AssertionException} with a given message. Use this method surrounded with
* {@code if} block with assert condition in case you plan to do string concatenation to produce
* the message.
*/
public static void assertUnreachable(String message) {
throw new AssertionException(message);
}

/**
* Asserts the given condition, throwing an {@link AssertionException} if the condition doesn't
* hold.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import com.facebook.react.animation.AnimationRegistry;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.SoftAssertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.uimanager.events.EventDispatcher;

/**
* Delegate of {@link UIManagerModule} that owns the native view hierarchy and mapping between
Expand Down Expand Up @@ -420,9 +418,10 @@ private void dropView(View view) {

public void removeRootView(int rootViewTag) {
UiThreadUtil.assertOnUiThread();
SoftAssertions.assertCondition(
mRootTags.get(rootViewTag),
"View with tag " + rootViewTag + " is not registered as a root view");
if (!mRootTags.get(rootViewTag)) {
SoftAssertions.assertUnreachable(
"View with tag " + rootViewTag + " is not registered as a root view");
}
View rootView = mTagsToViews.get(rootViewTag);
dropView(rootView);
mRootTags.delete(rootViewTag);
Expand Down Expand Up @@ -455,9 +454,10 @@ public int findTargetTagForTouch(int reactTag, float touchX, float touchY) {
}

public void setJSResponder(int reactTag, boolean blockNativeResponder) {
SoftAssertions.assertCondition(
!mRootTags.get(reactTag),
"Cannot block native responder on " + reactTag + " that is a root view");
if (mRootTags.get(reactTag)) {
SoftAssertions.assertUnreachable(
"Cannot block native responder on " + reactTag + " that is a root view");
}
ViewParent viewParent = blockNativeResponder ? mTagsToViews.get(reactTag).getParent() : null;
mJSResponderHandler.setJSResponder(reactTag, viewParent);
}
Expand Down

0 comments on commit 10a9b94

Please sign in to comment.