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

Reland arc cf2 (Draft for discussion) #38255

Closed
wants to merge 6 commits into from

Conversation

cyanglaz
Copy link
Contributor

This is a draft for discussion only. The result will be cooperated in #37883.

UInt32 length = [self readSize];
NSMutableArray* array = [NSMutableArray arrayWithCapacity:length];
UInt32 length = [codec readSize];
CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, length, &kCFTypeArrayCallBacks);
Copy link
Member

Choose a reason for hiding this comment

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

If you want to minimize the diff you could say:

CFMutableArrayRef array = (__bridge CFMutableArrayRef)[NSMutableArray arrayWithCapacity:length];

Then remove the CFAutorelease below.

Same thing for the dictionary below.

_range.length = length;
NSData* data = [_data subdataWithRange:_range];
_range.location += _range.length;
return data;
// return (CFDataRef)CFAutorelease((__bridge CFDataRef)data);
return (CFDataRef)CFRetain((__bridge CFDataRef)data);
Copy link
Member

Choose a reason for hiding this comment

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

So data is already on the autorelease pool here. You should just return it directly with the bridge cast.

return (__bridge CFDataRef)data;

}

- (NSString*)readUTF8 {
NSData* bytes = [self readData:[self readSize]];
return [[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding];
CFDataRef bytes = (CFDataRef)[self readDataRef:[self readSize]];
Copy link
Member

Choose a reason for hiding this comment

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

No need for a cast here.

NSData* bytes = [self readData:[self readSize]];
return [[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding];
CFDataRef bytes = (CFDataRef)[self readDataRef:[self readSize]];
NSData *data = (NSData*)CFBridgingRelease(bytes);
Copy link
Member

Choose a reason for hiding this comment

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

Why do you do CFBridgingRelease here instead of just using (__bridge)? bytes is already on the autorelease pool and initWithData:encoding: should retain it. There's no need to involve ARC. That's what we are trying to avoid =)

@jmagman
Copy link
Member

jmagman commented Dec 15, 2022

@cyanglaz can this be closed?

@cyanglaz cyanglaz closed this Mar 1, 2023
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.

3 participants