Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy method calls cleanup & IGListIndexSetResult hasChanges set to read only #403

Closed
wants to merge 0 commits into from

Conversation

AdamRobertsEF
Copy link

Removed copy method calls from objects and properties that aren’t weak references or blocks.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions.

@facebook-github-bot
Copy link
Contributor

@AdamRobertsEF updated the pull request - view changes

@AdamRobertsEF AdamRobertsEF changed the title Copy method calls cleanup Copy method calls cleanup & IGListIndexSetResult hasChanges set to read only Jan 10, 2017
Copy link
Contributor

@rnystrom rnystrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some examples in IGListAdapter that I linked to in #384 that we should also hit.

Some of these we actually need to keep. Anything coming from a public API should be copied so the consumer doesn't accidentally break something.

@@ -47,7 +47,7 @@ + (void)cleanIndexPathsWithMap:(const std::unordered_map<NSUInteger, IGListMoveI
indexPaths:(NSMutableSet<NSIndexPath *> *)indexPaths
deletes:(NSMutableIndexSet *)deletes
inserts:(NSMutableIndexSet *)inserts {
for (NSIndexPath *path in [indexPaths copy]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has to stay b/c otherwise we're mutating the array while enumerating

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a similar change to another indexSet method and undo it, missed this one.

_moveSections = mMoveSections;
_deleteIndexPaths = mDeleteIndexPaths;
_insertIndexPaths = mInsertIndexPaths;
_reloadIndexPaths = mReloadIndexPaths;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

_updates = updates;
_moves = moves;
_oldIndexPathMap = oldIndexPathMap;
_newIndexPathMap = newIndexPathMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I'd say this is good practice, but since this is part of the private API we're fine I think


/**
Returns whether the result has any changes or not.

@return `YES` if the result has changes, `NO` otherwise.
*/
- (BOOL)hasChanges;
@property (nonatomic, assign, readonly) BOOL hasChanges;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. We should probably revert this and handle #402 as a separate PR. Will require a changelog entry, etc.

_configureBlock = [configureBlock copy];
_sizeBlock = [sizeBlock copy];
_configureBlock = configureBlock;
_sizeBlock = sizeBlock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these get copied anyways

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the copy, then reverted my changes.

Same for the one below.

_configureBlock = [configureBlock copy];
_sizeBlock = [sizeBlock copy];
_configureBlock = configureBlock;
_sizeBlock = sizeBlock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -63,9 +63,9 @@ - (instancetype)initWithStoryboardCellIdentifier:(NSString *)identifier
IGParameterAssert(configureBlock != nil);
IGParameterAssert(sizeBlock != nil);
if (self = [super init]) {
_identifier = [identifier copy];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to stay b/c it is coming from consumers of the API. They could pass in an NSMutableString and change it later, breaking things.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -185,7 +185,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:
[cells addObject:cell];
}
}
return [cells copy];
return cells;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -55,7 +55,7 @@ - (NSInteger)sectionForSectionController:(IGListSectionController <IGListSection
- (void)updateWithObjects:(NSArray *)objects sectionControllers:(NSArray *)sectionControllers {
IGParameterAssert(objects.count == sectionControllers.count);

self.objects = [objects copy];
self.objects = objects;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a private class it'll be fine

@@ -108,7 +108,7 @@ - (void)updateObject:(id)object {

NSMutableArray *mobjects = [self.objects mutableCopy];
mobjects[section] = object;
self.objects = [mobjects copy];
self.objects = mobjects;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ok b/c its private. 👍

@jessesquires jessesquires added this to the 2.2.0 milestone Jan 10, 2017
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link
Contributor

@AdamRobertsEF updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@AdamRobertsEF updated the pull request - view changes

Copy link
Author

@AdamRobertsEF AdamRobertsEF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add as separate pull request.

@facebook-github-bot
Copy link
Contributor

@AdamRobertsEF updated the pull request - view changes

@rnystrom
Copy link
Contributor

@AdamRobertsEF are you splitting this into different PRs? Did you mean to close this one?

@AdamRobertsEF
Copy link
Author

I'm having fun with git.

I submitted the first pull request and the GitHub app put it into the prior pull request, when I submitted the second. I reversed the commit, to put it into a new PR. Then pulled everything from master to get my fork in sync with this one, and it cancelled the PR.

Let's close this one and I'll figure out how to do it better on the next pull request. :-)

@jessesquires jessesquires removed this from the 2.2.0 milestone Jan 12, 2017
@rnystrom
Copy link
Contributor

Quick note, need a new PR for this:

@jessesquires jessesquires modified the milestone: 2.2.0 Jan 18, 2017
@AdamRobertsEF
Copy link
Author

I'll create a new PR when the my last PR has been accepted. The GitHub app doesn't handle multiple PRs at the same time.

@rnystrom
Copy link
Contributor

@AdamRobertsEF which PR is that? You don't have any open atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants