Closed Bug 1447017 Opened 6 years ago Closed 6 years ago

Resize char-vector to input string length for String.prototype.toLocale{Lower,Upper}Case

Categories

(Core :: JavaScript: Internationalization API, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla61
Tracking Status
firefox61 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file, 1 obsolete file)

To minimize calls to ICU, the chars-vector should be resized to |Max(vector-inline-capacity, string-length)| before calling u_strToLower/u_strToUpper.
Attached patch bug1447017.patch (obsolete) — Splinter Review
The input string length is a better approximation for the final string length than the vector's inline capacity and it helps to reduce extra calls to ICU for large strings.
Attachment #8960184 - Flags: review?(jwalden+bmo)
Comment on attachment 8960184 [details] [diff] [review]
bug1447017.patch

Review of attachment 8960184 [details] [diff] [review]:
-----------------------------------------------------------------

It'd be nice eventually to have this not perform a copy if data exceeds on-stack length, a la StringBuffer::finishString, but good enough for now.
Attachment #8960184 - Flags: review?(jwalden+bmo) → review+
Comment on attachment 8960184 [details] [diff] [review]
bug1447017.patch

Review of attachment 8960184 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/builtin/String.cpp
@@ +1058,5 @@
>      // Maximum case mapping length is three characters.
>      static_assert(JSString::MAX_LENGTH < INT32_MAX / 3,
>                    "Case conversion doesn't overflow int32_t indices");
>  
> +    static const size_t INLINE_CAPACITY = 32;

Actually, use js::intl::INITIAL_CHAR_BUFFER_SIZE for this.
Priority: -- → P2
Attached patch bug1447017.patchSplinter Review
Updated to use js::intl::INITIAL_CHAR_BUFFER_SIZE per review comments. Carrying r+.
Attachment #8960184 - Attachment is obsolete: true
Attachment #8960973 - Flags: review+
(In reply to Jeff Walden [:Waldo] from comment #2)
> Comment on attachment 8960184 [details] [diff] [review]
> bug1447017.patch
> 
> Review of attachment 8960184 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> It'd be nice eventually to have this not perform a copy if data exceeds
> on-stack length, a la StringBuffer::finishString, but good enough for now.

Yes, there are unnecessary copies in both directions (when the input has two-byte, inline characters and when creating the output string). Maybe I'll take a look after ICU61 lands, because that'll include https://ssl.icu-project.org/trac/ticket/12647.
Pushed by apavel@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/6d8ff008a2e6
Resize char-vector to input string length for String.prototype.toLocale{Lower,Upper}Case. r=Waldo
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/6d8ff008a2e6
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: