<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#c27">Comment # 27</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>Thanks.

(In reply to <a href="show_bug.cgi?id=147602#c24">comment #24</a>)
<span class="quote">&gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=267982&amp;action=diff" name="attach_267982" title="Patch">attachment 267982</a> <a href="attachment.cgi?id=267982&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=267982&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=267982&amp;action=review</a>
&gt; 
&gt; Seems like a reasonable first cut. We need to remember to do some
&gt; performance testing and tuning on this; there’s a lot of memory allocation
&gt; here.
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:94
&gt; &gt; +static bool isWellFormedCurrencyCode(const String&amp; currency)
&gt; 
&gt; Might be worth marking some of these super-simple functions inline,
&gt; especially if they have only one or two call sites.</span >

Inlined.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:100
&gt; &gt; +static unsigned computeCurrencySortKey(const char* currency)
&gt; 
&gt; Ditto.</span >

Marked inline.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:106
&gt; &gt; +static unsigned extractCurrencySortKey(std::pair&lt;const char*, unsigned&gt;* currencyMinorUnit)
&gt; 
&gt; Ditto.</span >

I am not sure if it will make a difference, because we don't call this function here. We pass it to tryBinarySearch.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:143
&gt; &gt; +    std::array&lt;std::pair&lt;const char*, unsigned&gt;, 26&gt; currencyMinorUnits = { {
&gt; &gt; +        { &quot;BHD&quot;, 3 },
&gt; &gt; +        { &quot;BIF&quot;, 0 },
&gt; &gt; +        { &quot;BYR&quot;, 0 },
&gt; &gt; +        { &quot;CLF&quot;, 4 },
&gt; &gt; +        { &quot;CLP&quot;, 0 },
&gt; &gt; +        { &quot;DJF&quot;, 0 },
&gt; &gt; +        { &quot;GNF&quot;, 0 },
&gt; &gt; +        { &quot;IQD&quot;, 3 },
&gt; &gt; +        { &quot;ISK&quot;, 0 },
&gt; &gt; +        { &quot;JOD&quot;, 3 },
&gt; &gt; +        { &quot;JPY&quot;, 0 },
&gt; &gt; +        { &quot;KMF&quot;, 0 },
&gt; &gt; +        { &quot;KRW&quot;, 0 },
&gt; &gt; +        { &quot;KWD&quot;, 3 },
&gt; &gt; +        { &quot;LYD&quot;, 3 },
&gt; &gt; +        { &quot;OMR&quot;, 3 },
&gt; &gt; +        { &quot;PYG&quot;, 0 },
&gt; &gt; +        { &quot;RWF&quot;, 0 },
&gt; &gt; +        { &quot;TND&quot;, 3 },
&gt; &gt; +        { &quot;UGX&quot;, 0 },
&gt; &gt; +        { &quot;UYI&quot;, 0 },
&gt; &gt; +        { &quot;VND&quot;, 0 },
&gt; &gt; +        { &quot;VUV&quot;, 0 },
&gt; &gt; +        { &quot;XAF&quot;, 0 },
&gt; &gt; +        { &quot;XOF&quot;, 0 },
&gt; &gt; +        { &quot;XPF&quot;, 0 }
&gt; &gt; +    } };
&gt; 
&gt; I believe this will do some work every time the function is called. We need
&gt; to make sure this actually gets compiled in a way that doesn’t do the array
&gt; initialization each time, for efficiently. Might need to eschew the use of
&gt; std::array, or mark this as const, to achieve that.</span >

Changed it to std::pair&lt;const char*, unsigned&gt;[]. I tried using std::initializer_list but got an error saying that it &quot;does not provide a subscript operator&quot;.

<span class="quote">&gt; &gt; Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:144
&gt; &gt; +    std::pair&lt;const char*, unsigned&gt;* currencyMinorUnit = tryBinarySearch&lt;std::pair&lt;const char*, unsigned&gt;&gt;(currencyMinorUnits, currencyMinorUnits.size(), computeCurrencySortKey(currency.utf8().data()), extractCurrencySortKey);
&gt; 
&gt; Would read better with the use of auto*. Unclear on why we need to
&gt; explicitly pass the type in when invoking the tryBinarySearch function
&gt; template; I’d expect it to work without specifying that explicitly.</span >

Used auto*. It looks like we have to explicitly pass the type. Otherwise, I get this error:

/WebKit/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:145:31: error: no matching function for call to 'tryBinarySearch'
    auto* currencyMinorUnit = tryBinarySearch(currencyMinorUnits, WTF_ARRAY_LENGTH(currencyMinorUnits), computeCurrencySortKey(StringView(currency)), extractCurrencySortKey);
                              ^~~~~~~~~~~~~~~

...

/WebKit/WebKitBuild/Debug/usr/local/include/wtf/StdLibExtras.h:240:26: note: candidate template ignored: couldn't infer template argument 'ArrayElementType'
inline ArrayElementType* tryBinarySearch(ArrayType&amp; array, size_t size, KeyType key, ExtractKey extractKey = ExtractKey())

<span class="quote">&gt; Should overload computeCurrencySortKey to work on a const String&amp; or
&gt; StringView correctly; doing memory allocation just to convert the String to
&gt; a CString, just to get the first three characters of the string, is not
&gt; great.</span >

Done.</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>