Skip to content

Commit

Permalink
Follow-up to 270645@main to address review feedback
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264759

Reviewed by Darin Adler.

Follow-up to 270645@main to address review feedback from Darin. Use Vector
constructor / WTF::map() when possible instead of an append*() function.

There are a couple of cases in 270645@main where I keep using append*() even
though they were calling reserveInitialCapacity() before because the vectors
in question have an inline buffer and doing a Vector move assignment may end
up having to copy the values in the inline buffers over.

* Source/JavaScriptCore/runtime/IntlObject.cpp:
(JSC::intlAvailableCalendars):
* Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::copyDisjunction):

Canonical link: https://commits.webkit.org/270679@main
  • Loading branch information
cdumez committed Nov 13, 2023
1 parent e72572d commit 1dfe581
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions Source/JavaScriptCore/runtime/IntlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,6 @@ const Vector<String>& intlAvailableCalendars()
static LazyNeverDestroyed<Vector<String>> availableCalendars;
static std::once_flag initializeOnce;
std::call_once(initializeOnce, [&] {
availableCalendars.construct();
ASSERT(availableCalendars->isEmpty());

UErrorCode status = U_ZERO_ERROR;
auto enumeration = std::unique_ptr<UEnumeration, ICUDeleter<uenum_close>>(ucal_getKeywordValuesForLocale("calendars", "und", false, &status));
ASSERT(U_SUCCESS(status));
Expand All @@ -1638,7 +1635,7 @@ const Vector<String>& intlAvailableCalendars()
return StringImpl::createStaticStringImpl(string.characters16(), string.length());
};

availableCalendars->appendUsingFunctor(count, [&](size_t) {
availableCalendars.construct(count, [&](size_t) {
int32_t length = 0;
const char* pointer = uenum_next(enumeration.get(), &length, &status);
ASSERT(U_SUCCESS(status));
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/yarr/YarrPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ class YarrPatternConstructor {
}
PatternAlternative* newAlternative = newDisjunction->addNewAlternative(alternative->m_firstSubpatternId, alternative->matchDirection());
newAlternative->m_lastSubpatternId = alternative->m_lastSubpatternId;
newAlternative->m_terms.appendContainerWithMapping(alternative->m_terms, [&](auto& term) {
newAlternative->m_terms = WTF::map(alternative->m_terms, [&](auto& term) {
return copyTerm(term, filterStartsWithBOL);
});
}
Expand Down

0 comments on commit 1dfe581

Please sign in to comment.