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

[iOS] Fabric: Add missing source properties of Image #46460

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zhongwuzw
Copy link
Contributor

Summary:

Fabric: Add missing source properties of Image

Changelog:

[IOS] [FIXED] - Fabric: Add missing source properties of Image

Test Plan:

Missing props should worked.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 12, 2024
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

There have been some feedback internally on the change, to improve this.
Could you please have a look at them and apply them?

Comment on lines 127 to 131
method = [[NSString alloc] initWithBytesNoCopy:(void *)imageSource.method.c_str()
length:imageSource.method.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO]
.uppercaseString
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we just do?

Suggested change
method = [[NSString alloc] initWithBytesNoCopy:(void *)imageSource.method.c_str()
length:imageSource.method.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO]
.uppercaseString
method = [[NSString alloc] initWithUTF8String:imageSource.method.c_str()].uppercaseString;

also, no need for the ?: fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Emm, I used no copy method because I think it can reduce one copy, if we use initWithUTF8String, it would produces twice copy operations from c_str to nsadata.

length:imageSource.body.size()
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
body = [RCTConvert NSData:bodyString];
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we just initialize it with some NSData initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems no suitable initializer...

Copy link
Contributor

Choose a reason for hiding this comment

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

the initializer should be:

[NSData dataWithBytes:imageSource.body.c_str() length:imageSource.body.size()]

We use this also in other locations, like here

Copy link
Contributor Author

@zhongwuzw zhongwuzw Sep 18, 2024

Choose a reason for hiding this comment

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

@cipolleschi I updated. But they are maybe different when bytes are not a valid UTF-8 bytes?

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

See comment in NSData initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants