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

Implement NSIndexSet enumeration and *PassingTest apis #2268

Merged
merged 4 commits into from
Mar 20, 2017

Conversation

aballway
Copy link
Contributor

Fixes #2076
Fixes #2077

- (NSIndexSet*)indexesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger, BOOL*))predicate;
- (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger, BOOL*))predicate;
- (NSIndexSet*)indexesInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger, BOOL*))predicate;
- (void)enumerateRangesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange, BOOL*))block;
Copy link
Contributor

Choose a reason for hiding this comment

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

opts [](start = 76, length = 4)

nit: Update var names to reflect changes in NSIndexSet.mm

UNIMPLEMENTED();
return StubReturn();
- (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)options passingTest:(BOOL (^)(NSUInteger, BOOL*))predicate {
NSIndexSet* set = [self indexesInRange:range options:options passingTest:predicate];

Choose a reason for hiding this comment

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

*stop optimization?

- (void)enumerateRangesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange, BOOL*))block {
UNIMPLEMENTED();
- (void)enumerateRangesUsingBlock:(void (^)(NSRange, BOOL*))block {
[self enumerateRangesWithOptions:0 usingBlock:block];

Choose a reason for hiding this comment

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

please always call the most-specific version in these shim implementations; you'll avoid an entire level of dynamic dispatch and a stack frame.

}

if (indexRange) {
*indexRange = { j, range.location + range.length - j };

Choose a reason for hiding this comment

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

huh; indexRange is in/out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup 🇫🇰

for (NSUInteger i = start; i != end && stop == NO; i += step) {
NSRange intersection = NSIntersectionRange(range, ranges[i - 1]);
if (intersection.length != 0) {
NSUInteger rangeStart = reverse ? intersection.location + intersection.length : intersection.location + 1;

Choose a reason for hiding this comment

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

you're right, this DOES seem like it should be able to be lifted out/commonized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IKR. Unfortunately, in the concurrent case we'd be doing two levels of dispatch_group_async which seems sillier than very similar but not identical code

}

return ret;
}];
return (options & NSEnumerationReverse) ? [set lastIndex] : [set firstIndex];

Choose a reason for hiding this comment

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

since set will contain only one index, this is no longer necessary

@DHowett-MSFT
Copy link

nit: because this is a set, the set will set set

Copy link

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

(set)

@aballway aballway merged commit 707d12c into microsoft:develop Mar 20, 2017
@aballway aballway deleted the indexset branch April 25, 2017 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants