<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - [INTL] Implement Intl.NumberFormat.prototype.resolvedOptions ()"
href="https://bugs.webkit.org/show_bug.cgi?id=147602#c20">Comment # 20</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - [INTL] Implement Intl.NumberFormat.prototype.resolvedOptions ()"
href="https://bugs.webkit.org/show_bug.cgi?id=147602">bug 147602</a>
from <span class="vcard"><a class="email" href="mailto:sukolsak@gmail.com" title="Sukolsak Sakshuwong <sukolsak@gmail.com>"> <span class="fn">Sukolsak Sakshuwong</span></a>
</span></b>
<pre>(In reply to <a href="show_bug.cgi?id=147602#c18">comment #18</a>)
<span class="quote">> Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=267624&action=diff" name="attach_267624" title="Patch">attachment 267624</a> <a href="attachment.cgi?id=267624&action=edit" title="Patch">[details]</a></span>
> Patch
>
> View in context:
> <a href="https://bugs.webkit.org/attachment.cgi?id=267624&action=review">https://bugs.webkit.org/attachment.cgi?id=267624&action=review</a>
>
> > Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:92
> > + Vector<String> keyLocaleData({
>
> Seems unfortunate to re-create this vector every time the function is
> called. Might consider changing the function’s interface to return a const&
> unless it can involve computing a unique value and using a static
> NeverDestroyed for this particular case.</span >
This function is passed to resolveLocale. Other classes that use resolveLocale can pass functions that compute a unique value to it, such as sortLocaleData in IntlCollator.cpp.
There is a way to optimize it, which requires some changes to the algorithm in the spec. But I think we should wait until all Intl classes are implemented first.
<span class="quote">> > Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:158
> > + for (const auto& currencyMinorUnit : currencyMinorUnits) {
>
> This list might be long enough that's binary search would be faster than a
> linear one.</span >
Done. Not sure if I do it correctly. Could you please take a look?
<span class="quote">> > Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:159
> > + if (currency == currencyMinorUnit.first)
>
> Is it correct that this is a case sensitive check?</span >
Yes, it is correct. Before we call we this function, we convert the currency to uppercase letters.
<span class="quote">> > Source/JavaScriptCore/runtime/IntlObject.cpp:239
> > + if (std::isnan(doubleValue) || doubleValue < static_cast<double>(minimum) || doubleValue > static_cast<double>(maximum)) {
>
> There is a way to write this without an explicit check for NaN.
>
> If (!(x >= min && x <= max))</span >
Done. Nice trick!
<span class="quote">> > Source/JavaScriptCore/runtime/IntlObject.cpp:245
> > + return static_cast<unsigned>(doubleValue);
>
> This has peculiar behavior for max + 0.1; do we have test cases that cover
> values just slightly under min and slightly over max?</span >
Yes, we have test cases for those cases. For example, the allowed range of minimumIntegerDigits is [1, 21]. So, we test
- 0 (throws)
- 0.9 (throws)
- 1
- 21
- 21.1 (throws)
- 22 (throws)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>