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

Update enumeration methods to allow a stop flag to be flipped by caller #204

Merged
merged 5 commits into from
Oct 4, 2017
Merged

Update enumeration methods to allow a stop flag to be flipped by caller #204

merged 5 commits into from
Oct 4, 2017

Conversation

mjlazar
Copy link
Contributor

@mjlazar mjlazar commented Oct 3, 2017

No description provided.

@ghost
Copy link

ghost commented Oct 3, 2017

🚫 CI failed with log

@@ -562,7 +562,10 @@ - (void)enumerateObjectsWithBlock:(PINCacheObjectBlock)block
for (NSString *key in keysSortedByDate) {
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
block(self, key, _dictionary[key]);
BOOL stop;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is unsafe? If the block doesn't set the stop value this will be garbage, not NO? I think only ivars are automatically initialized to zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Value types are always initialized to zero when they're allocated on the stack. Happy to change this to make it more readable though.

@@ -1106,7 +1106,10 @@ - (void)enumerateObjectsWithBlock:(PINDiskCacheFileURLBlock)block
NSURL *fileURL = [self encodedFileURLForKey:key];
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
block(key, fileURL);
BOOL stop;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you initialize this to NO (same comment as below).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

BOOL stop;
block(key, fileURL, &stop);
if (stop)
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

super nit, but can you do 4 spaces here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would recommend creating a .clang-format file containing your specific style rules. It works great with objc, and you could probably integrate it as a presubmit check on your CI.

See https://clang.llvm.org/docs/ClangFormat.html.

BOOL stop;
block(self, key, _dictionary[key], &stop);
if (stop)
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

4 species please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -827,7 +830,12 @@ - (void)removeAllObjects:(nullable PINMemoryCacheBlock)block

- (void)enumerateObjectsWithBlock:(PINMemoryCacheObjectBlock)block completionBlock:(nullable PINMemoryCacheBlock)completionBlock
{
[self enumerateObjectsWithBlockAsync:block completionBlock:completionBlock];
[self enumerateObjectsWithBlockAsync:^(id<PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL * _Nonnull stop) {
if ([cache isKindOfClass:[PINMemoryCache class]]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

4 space indentation (sorry) 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@garrettmoon
Copy link
Collaborator

Thank you for the contribution, this will be super useful!

Copy link
Collaborator

@maicki maicki left a comment

Choose a reason for hiding this comment

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

This will be really great to have!

@garrettmoon This will basically be a breaking API change, should we add a new API for it or go with it?

@garrettmoon
Copy link
Collaborator

@maicki I think go for it because we're still in beta territory?

Copy link
Collaborator

@garrettmoon garrettmoon left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @mjlazar !

@garrettmoon garrettmoon merged commit 084ad3e into pinterest:master Oct 4, 2017
@mjlazar mjlazar deleted the enumerate-objects-improvements branch October 4, 2017 19:46
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.

3 participants