[Webkit-unassigned] [Bug 158188] [INTL] Implement the caseFirst option for Intl.Collator

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon May 30 20:52:53 PDT 2016


https://bugs.webkit.org/show_bug.cgi?id=158188

Darin Adler <darin at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #280100|review?                     |review+
              Flags|                            |

--- Comment #5 from Darin Adler <darin at apple.com> ---
Comment on attachment 280100
  --> https://bugs.webkit.org/attachment.cgi?id=280100
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=280100&action=review

> Source/JavaScriptCore/runtime/IntlCollator.cpp:289
>      m_numeric = (result.get(ASCIILiteral("kn")) == "true");

I’d like how this reads better without the parentheses.

> Source/JavaScriptCore/runtime/IntlCollator.cpp:290
> +    const String& caseFirst = result.get(ASCIILiteral("kf"));

As with the cases below, I think it’s nicer to have the translation from string to CaseFirst be in a helper function. It can be inlined if we like.

> Source/JavaScriptCore/runtime/IntlCollator.cpp:296
> +        ASSERT(caseFirst == "false");

Why can we assert this? What prevents invalid values?

> Source/JavaScriptCore/runtime/IntlCollator.cpp:389
> +    UColAttributeValue caseFirst;
> +    switch (m_caseFirst) {
> +    case CaseFirst::Upper:
> +        caseFirst = UCOL_UPPER_FIRST;
> +        break;
> +    case CaseFirst::Lower:
> +        caseFirst = UCOL_LOWER_FIRST;
> +        break;
> +    case CaseFirst::False:
> +        caseFirst = UCOL_OFF;
> +        break;
> +    default:
> +        ASSERT_NOT_REACHED();
> +    }

It’s a better idiom to put this kind of translation into a helper function that takes a CaseFirst and returns a UColAttributeValue. Then we can use return inside the switch cases, so we can put the ASSERT_NOT_REACHED outside the switch instead of in a default case, and the compiler will give us a warning if we ever leave a case out. It also makes the main code flow easier to read and helps us spot if we made a mistake.

This would be similar to the caseFirstString function. It can be inlined if we like.

Only trick might be using the UColAttributeValue type in the class header without including ICU headers.

> Source/JavaScriptCore/runtime/IntlCollator.cpp:451
> +const char* IntlCollator::caseFirstString(CaseFirst caseFirst)

I think we should probably mark this function inline.

> Source/JavaScriptCore/runtime/IntlCollator.cpp:462
> +    return nullptr;

I think we should return "false" here instead of nullptr.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20160531/dd75c341/attachment.html>


More information about the webkit-unassigned mailing list