Bug 154486 - Improvements to Intl code
Summary: Improvements to Intl code
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-19 18:24 PST by Sukolsak Sakshuwong
Modified: 2016-02-21 17:55 PST (History)
9 users (show)

See Also:


Attachments
Patch (21.14 KB, patch)
2016-02-19 18:33 PST, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff
Patch (21.23 KB, patch)
2016-02-19 19:08 PST, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff
Patch (21.14 KB, patch)
2016-02-19 19:10 PST, Sukolsak Sakshuwong
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sukolsak Sakshuwong 2016-02-19 18:24:25 PST
- Use std::unique_ptr to store ICU objects (See Comment 10 in https://bugs.webkit.org/show_bug.cgi?id=147603#c10)
- Pass Vector::size() to ICU functions that take a buffer size instead of Vector::capacity()
- If U_SUCCESS(status) is true, it means there is no error, but there could be warnings. ICU functions ignore warnings. So, there is no need to reset status to U_ZERO_ERROR.
- Remove the initialization of the String instance variables of IntlDateTimeFormat. These values are never read and cause unnecessary memory allocation.
- Fix coding style
Comment 1 Sukolsak Sakshuwong 2016-02-19 18:33:57 PST
Created attachment 271835 [details]
Patch
Comment 2 Sukolsak Sakshuwong 2016-02-19 18:43:43 PST
Oops, wrong link. For the comment about std::unique_ptr, see Comment 10 in https://bugs.webkit.org/show_bug.cgi?id=147605#c10
Comment 3 Andy VanWagoner 2016-02-19 18:58:45 PST
Comment on attachment 271835 [details]
Patch

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

> Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp:674
> +    m_dateFormat = std::unique_ptr<UDateFormat, UDateFormatDeleter>(udat_open(UDAT_IGNORE, UDAT_IGNORE, m_locale.utf8().data(), timeZoneView.upconvertedCharacters(), timeZoneView.length(), pattern.upconvertedCharacters(), pattern.length(), &status));

Since ICU headers were updated to v52, UDAT_PATTERN is preferred over UDAT_IGNORE. Mind changing that while you are in here?
Comment 4 Sukolsak Sakshuwong 2016-02-19 19:08:45 PST
Created attachment 271839 [details]
Patch
Comment 5 Sukolsak Sakshuwong 2016-02-19 19:10:45 PST
Created attachment 271840 [details]
Patch
Comment 6 Sukolsak Sakshuwong 2016-02-19 19:11:52 PST
(In reply to comment #3)
> Comment on attachment 271835 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=271835&action=review
> 
> > Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp:674
> > +    m_dateFormat = std::unique_ptr<UDateFormat, UDateFormatDeleter>(udat_open(UDAT_IGNORE, UDAT_IGNORE, m_locale.utf8().data(), timeZoneView.upconvertedCharacters(), timeZoneView.length(), pattern.upconvertedCharacters(), pattern.length(), &status));
> 
> Since ICU headers were updated to v52, UDAT_PATTERN is preferred over
> UDAT_IGNORE. Mind changing that while you are in here?

Done. Thanks!
Comment 7 Michael Catanzaro 2016-02-21 08:24:54 PST
Comment on attachment 271840 [details]
Patch

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

> Source/JavaScriptCore/runtime/IntlCollator.cpp:329
> +    auto collator = std::unique_ptr<UCollator, UCollatorDeleter>(ucol_open(m_locale.utf8().data(), &status));

Use std::make_unique from StdLibExtras.h
Comment 8 Sukolsak Sakshuwong 2016-02-21 13:27:03 PST
(In reply to comment #7)
> Comment on attachment 271840 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=271840&action=review
> 
> > Source/JavaScriptCore/runtime/IntlCollator.cpp:329
> > +    auto collator = std::unique_ptr<UCollator, UCollatorDeleter>(ucol_open(m_locale.utf8().data(), &status));
> 
> Use std::make_unique from StdLibExtras.h

I don't think that works, because ucol_open is not a C++ constructor.
Comment 9 Darin Adler 2016-02-21 17:15:40 PST
Comment on attachment 271840 [details]
Patch

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

>>> Source/JavaScriptCore/runtime/IntlCollator.cpp:329
>>> +    auto collator = std::unique_ptr<UCollator, UCollatorDeleter>(ucol_open(m_locale.utf8().data(), &status));
>> 
>> Use std::make_unique from StdLibExtras.h
> 
> I don't think that works, because ucol_open is not a C++ constructor.

That’s right. Can’t use make_unique here.
Comment 10 WebKit Commit Bot 2016-02-21 17:55:38 PST
Comment on attachment 271840 [details]
Patch

Clearing flags on attachment: 271840

Committed r196887: <http://trac.webkit.org/changeset/196887>
Comment 11 WebKit Commit Bot 2016-02-21 17:55:42 PST
All reviewed patches have been landed.  Closing bug.