Bug 211499 - Make a helper for ICU functions that may need to be called twice to populate a buffer
Summary: Make a helper for ICU functions that may need to be called twice to populate ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-05 23:37 PDT by Darin Adler
Modified: 2020-05-06 16:02 PDT (History)
12 users (show)

See Also:


Attachments
Patch (30.64 KB, patch)
2020-05-05 23:39 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (31.91 KB, patch)
2020-05-06 08:08 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (32.06 KB, patch)
2020-05-06 09:13 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (32.49 KB, patch)
2020-05-06 14:06 PDT, Darin Adler
ross.kirsling: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2020-05-05 23:37:42 PDT
Make a helper for the pattern of ICU functions that may need to be called twice to populate a buffer
Comment 1 Darin Adler 2020-05-05 23:39:46 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-05-05 23:40:35 PDT
Looking for feedback on the name of the function template, and also the other design considerations.
Comment 3 Darin Adler 2020-05-06 00:01:34 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-05-06 08:08:14 PDT Comment hidden (obsolete)
Comment 5 Darin Adler 2020-05-06 08:20:32 PDT Comment hidden (obsolete)
Comment 6 Darin Adler 2020-05-06 08:58:37 PDT Comment hidden (obsolete)
Comment 7 Darin Adler 2020-05-06 09:13:33 PDT Comment hidden (obsolete)
Comment 8 Darin Adler 2020-05-06 11:38:30 PDT Comment hidden (obsolete)
Comment 9 Darin Adler 2020-05-06 14:06:17 PDT
Created attachment 398655 [details]
Patch
Comment 10 Ross Kirsling 2020-05-06 14:22:36 PDT
Comment on attachment 398655 [details]
Patch

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

r=me pending EWS, this is really cool.

> Source/WTF/ChangeLog:10
> +        specia considerations because of null character terminatorion, or destinations that are

spelling: specia, terminatorion

> Source/WTF/wtf/unicode/icu/ICUHelpers.h:77
> +template<typename FirstArgumentType, typename ...OtherArgumentTypes> auto argumentTuple(FirstArgumentType&&, OtherArgumentTypes&&...);

How come this declaration is needed for argumentTuple but not for findVector?
Comment 11 Darin Adler 2020-05-06 14:31:22 PDT
Comment on attachment 398655 [details]
Patch

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

>> Source/WTF/ChangeLog:10
>> +        specia considerations because of null character terminatorion, or destinations that are
> 
> spelling: specia, terminatorion

OK, I’ll fix those.

>> Source/WTF/wtf/unicode/icu/ICUHelpers.h:77
>> +template<typename FirstArgumentType, typename ...OtherArgumentTypes> auto argumentTuple(FirstArgumentType&&, OtherArgumentTypes&&...);
> 
> How come this declaration is needed for argumentTuple but not for findVector?

Must admit I am not 100% sure. Without it, the code does not compile, though!
Comment 12 Saam Barati 2020-05-06 14:40:10 PDT
Comment on attachment 398655 [details]
Patch

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

LGTM too

> Source/WTF/wtf/unicode/icu/ICUHelpers.h:81
> +    return tuple_cat(std::make_tuple(buffer.data(), buffer.size()), argumentTuple(std::forward<OtherArgumentTypes>(otherArguments)...));

Nice

> Source/WTF/wtf/unicode/icu/ICUHelpers.h:91
> +template<typename FunctionType, typename ...ArgumentTypes> UErrorCode callBufferProducingFunction(const FunctionType& function, ArgumentTypes&&... arguments)

This is nice. I like how you solved passing in a Vector
Comment 13 Darin Adler 2020-05-06 14:56:59 PDT
Comment on attachment 398655 [details]
Patch

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

>>> Source/WTF/wtf/unicode/icu/ICUHelpers.h:77
>>> +template<typename FirstArgumentType, typename ...OtherArgumentTypes> auto argumentTuple(FirstArgumentType&&, OtherArgumentTypes&&...);
>> 
>> How come this declaration is needed for argumentTuple but not for findVector?
> 
> Must admit I am not 100% sure. Without it, the code does not compile, though!

Oh, I figured it out. The difference is that the Vector overload of findVector never recursively calls the other findVector; just returns the reference to the vector. But in the case of argumentTuple, the overload that handles the Vector *does* recursively call argumentTuple. And to resolve it correctly it apparently needs to have already seen the template declaration.
Comment 14 Darin Adler 2020-05-06 15:00:29 PDT
Comment on attachment 398655 [details]
Patch

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

> Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp:622
> -    Vector<UChar, 32> patternBuffer(32);
> -    status = U_ZERO_ERROR;
> -    auto patternLength = udatpg_getBestPatternWithOptions(generator, skeletonView.upconvertedCharacters(), skeletonView.length(), UDATPG_MATCH_HOUR_FIELD_LENGTH, patternBuffer.data(), patternBuffer.size(), &status);
> -    if (needsToGrowToProduceBuffer(status)) {
> -        status = U_ZERO_ERROR;
> -        patternBuffer.grow(patternLength);
> -        udatpg_getBestPattern(generator, skeletonView.upconvertedCharacters(), skeletonView.length(), patternBuffer.data(), patternLength, &status);
> -    }
> +    Vector<UChar, 32> patternBuffer;
> +    status = callBufferProducingFunction(udatpg_getBestPatternWithOptions, generator, skeletonView.upconvertedCharacters(), skeletonView.length(), UDATPG_MATCH_HOUR_FIELD_LENGTH, patternBuffer);

I just noticed a behavior change here.

The old code called udatpg_getBestPatternWithOptions first, but then called udatpg_getBestPattern the second time. I suspect the refactoring fixed a potential bug.
Comment 15 Darin Adler 2020-05-06 16:01:11 PDT
Committed r261257: <https://trac.webkit.org/changeset/261257>
Comment 16 Radar WebKit Bug Importer 2020-05-06 16:02:17 PDT
<rdar://problem/62949588>