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

feat: Add v8::icu::get_language_tag() #953

Merged
merged 14 commits into from
Oct 5, 2022

Conversation

AnInternetTroll
Copy link
Contributor

closes #797

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2022

CLA assistant check
All committers have signed the CLA.

@bartlomieju bartlomieju changed the title feat: Add v8::icu::get_default_locale function feat: Add v8::icu::get_language_tag() Sep 30, 2022
src/binding.cc Outdated Show resolved Hide resolved
@ry
Copy link
Member

ry commented Sep 30, 2022

What do you need this for?

@bartlomieju
Copy link
Member

What do you need this for?

Needed for denoland/deno#12322

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

icu_get_default_locale is doing 3 allocations! Is there a reason? You can just not copy at all:

const char* icu_get_default_locale(size_t* len) {
   // ...
   *len = tag.size();
   return tag.data();
}
let mut len = 0;
let locale: *const u8 = unsafe { icu_get_default_locale(&mut len) };
let bytes = unsafe { std::slice::from_raw_parts(locale, len) };
unsafe { String::from_utf8_unchecked(bytes) }

@bartlomieju
Copy link
Member

@littledivy I don't think that would work - the data you get from ICU is stack-allocated and as such can't return it to Rust.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju merged commit 760c48a into denoland:main Oct 5, 2022
@ghost ghost mentioned this pull request Oct 9, 2022
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.

Expose default locale
6 participants