<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&#64;gmail.com" title="Sukolsak Sakshuwong &lt;sukolsak&#64;gmail.com&gt;"> <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">&gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=267624&amp;action=diff" name="attach_267624" title="Patch">attachment 267624</a> <a href="attachment.cgi?id=267624&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=267624&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=267624&amp;action=review</a>
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:92
&gt; &gt; +    Vector&lt;String&gt; keyLocaleData({
&gt; 
&gt; Seems unfortunate to re-create this vector every time the function is
&gt; called. Might consider changing the function’s interface to return a const&amp;
&gt; unless it can involve computing a unique value and using a static
&gt; 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">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:158
&gt; &gt; +    for (const auto&amp; currencyMinorUnit : currencyMinorUnits) {
&gt; 
&gt; This list might be long enough that's binary search would be faster than a
&gt; linear one.</span >

Done. Not sure if I do it correctly. Could you please take a look?

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:159
&gt; &gt; +        if (currency == currencyMinorUnit.first)
&gt; 
&gt; 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">&gt; &gt; Source/JavaScriptCore/runtime/IntlObject.cpp:239
&gt; &gt; +        if (std::isnan(doubleValue) || doubleValue &lt; static_cast&lt;double&gt;(minimum) || doubleValue &gt; static_cast&lt;double&gt;(maximum)) {
&gt; 
&gt; There is a way to write this without an explicit check for NaN.
&gt; 
&gt;     If (!(x &gt;= min &amp;&amp; x &lt;= max))</span >

Done. Nice trick!

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlObject.cpp:245
&gt; &gt; +        return static_cast&lt;unsigned&gt;(doubleValue);
&gt; 
&gt; This has peculiar behavior for max + 0.1; do we have test cases that cover
&gt; 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>