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

Add LanguageIdentifier::cmp_bytes #1704

Merged
merged 7 commits into from
Mar 17, 2022
Merged

Conversation

sffc
Copy link
Member

@sffc sffc commented Mar 16, 2022

Part of #831

I opened #1703 to think about how to scale this to Locale.

@sffc sffc requested review from Manishearth and removed request for nciric March 16, 2022 08:29
@sffc
Copy link
Member Author

sffc commented Mar 16, 2022

Although it wasn't the goal of this PR, if you like what I do here, I could replace other impls like PartialEq<str> and Writeable to use LanguageIdentifierSubtagIterator.

zbraniecki
zbraniecki previously approved these changes Mar 16, 2022
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm!

components/locid/src/cmp/langid.rs Outdated Show resolved Hide resolved
components/locid/src/langid.rs Show resolved Hide resolved
Manishearth
Manishearth previously approved these changes Mar 16, 2022
Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

lgtm with nit fixed

@sffc sffc dismissed stale reviews from Manishearth and zbraniecki via 4fe02c0 March 17, 2022 06:47
@sffc sffc requested a review from zbraniecki March 17, 2022 06:48
@sffc
Copy link
Member Author

sffc commented Mar 17, 2022

Although it wasn't the goal of this PR, if you like what I do here, I could replace other impls like PartialEq<str> and Writeable to use LanguageIdentifierSubtagIterator.

I tried it for Writeable and I can't beat the performance from our current Writeable impl, so although it slightly cleans up the code, I'll leave it as-is, at least for LanguageIdentifier. It may be more worthwhile in Locale.

I could simplify PartialEq<str>, but it would change the semantics due to the lenient/strict comparison issue Zibi pointed out. This also means that I can't implement PartialOrd<str> based on cmp_bytes because it has different semantics.

This means I'm adding code without deleting code, which isn't great, but this function has a specific purpose and use case.

} else {
return None;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

optional, n-b:

return self.langid.variants.get(i).map(||);

Copy link
Member Author

Choose a reason for hiding this comment

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

The main thing to be done inside the map closure would be to update the state variant. I think I prefer using a more procedural code style in this function since it is a nontrivial function and involves mutable state.

@sffc sffc merged commit fa4fd56 into unicode-org:main Mar 17, 2022
@sffc sffc deleted the langid-bcp47-cmp branch March 17, 2022 21:15
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