Using `indexOfObjectIdenticalTo` instead of `indexOfObject` in RCTUIManager

Summary:
This should be much more performant (and it better illustrates the intension of the code).
The fix was suggested by Adlai-Holler.

Reviewed By: mmmulani

Differential Revision: D5851595

fbshipit-source-id: 45d172a5fa796549c6dcea8f35c5cbb2a4c2d2e0
This commit is contained in:
Valentin Shergin 2017-09-18 15:32:51 -07:00 committed by Facebook Github Bot
parent d7f6208649
commit 9d9e250d28
1 changed files with 2 additions and 2 deletions

View File

@ -768,7 +768,7 @@ RCT_EXPORT_METHOD(removeSubviewsFromContainerWithID:(nonnull NSNumber *)containe
// So, let's temporary restore the view back after removing. // So, let's temporary restore the view back after removing.
// To do so, we have to memorize original `superview` (which can differ from `container`) and an index of removed view. // To do so, we have to memorize original `superview` (which can differ from `container`) and an index of removed view.
UIView *originalSuperview = removedChild.superview; UIView *originalSuperview = removedChild.superview;
NSUInteger originalIndex = [originalSuperview.subviews indexOfObject:removedChild]; NSUInteger originalIndex = [originalSuperview.subviews indexOfObjectIdenticalTo:removedChild];
[container removeReactSubview:removedChild]; [container removeReactSubview:removedChild];
[originalSuperview insertSubview:removedChild atIndex:originalIndex]; [originalSuperview insertSubview:removedChild atIndex:originalIndex];
@ -821,7 +821,7 @@ RCT_EXPORT_METHOD(replaceExistingNonRootView:(nonnull NSNumber *)reactTag
return; return;
} }
NSUInteger indexOfView = [superShadowView.reactSubviews indexOfObject:shadowView]; NSUInteger indexOfView = [superShadowView.reactSubviews indexOfObjectIdenticalTo:shadowView];
RCTAssert(indexOfView != NSNotFound, @"View's superview doesn't claim it as subview (id %@)", reactTag); RCTAssert(indexOfView != NSNotFound, @"View's superview doesn't claim it as subview (id %@)", reactTag);
NSArray<NSNumber *> *removeAtIndices = @[@(indexOfView)]; NSArray<NSNumber *> *removeAtIndices = @[@(indexOfView)];
NSArray<NSNumber *> *addTags = @[newReactTag]; NSArray<NSNumber *> *addTags = @[newReactTag];