Skip to content

Commit

Permalink
Drop StringView constructors taking in raw pointers
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271512

Reviewed by Darin Adler and Sihui Liu.

Drop StringView constructors taking in raw pointers, in favor of the ones taking in a std::span.

* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/ExceptionHelpers.cpp:
(JSC::notAFunctionSourceAppender):
* Source/JavaScriptCore/runtime/ISO8601.cpp:
(JSC::ISO8601::parseDuration):
* Source/JavaScriptCore/runtime/IntlCollator.cpp:
(JSC::IntlCollator::checkICULocaleInvariants):
* Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp:
(JSC::canonicalizeTimeZoneName):
(JSC::IntlDateTimeFormat::initializeDateTimeFormat):
(JSC::IntlDateTimeFormat::formatToParts const):
(JSC::IntlDateTimeFormat::formatRangeToParts):
* Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:
(JSC::IntlDurationFormat::formatToParts const):
* Source/JavaScriptCore/runtime/IntlListFormat.cpp:
(JSC::IntlListFormat::formatToParts const):
* Source/JavaScriptCore/runtime/IntlLocale.cpp:
(JSC::IntlLocale::hourCycles):
* Source/JavaScriptCore/runtime/IntlNumberFormat.cpp:
(JSC::IntlNumberFormat::formatRangeToPartsInternal):
* Source/JavaScriptCore/runtime/JSString.h:
(JSC::JSRopeString::unsafeView const):
(JSC::JSRopeString::viewWithUnderlyingString const):
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::LiteralParser<CharType>::Lexer::lex):
(JSC::LiteralParser<CharType>::Lexer::lexStringSlow):
(JSC::LiteralParser<CharType>::parsePrimitiveValue):
* Source/JavaScriptCore/wasm/WasmIndexOrName.cpp:
(JSC::Wasm::makeString):
* Source/WTF/wtf/HexNumber.cpp:
(WTF::printInternal):
* Source/WTF/wtf/HexNumber.h:
(WTF::HexNumberBuffer::span const):
* Source/WTF/wtf/URL.cpp:
(WTF::URL::setHost):
(WTF::URL::setHostAndPort):
* Source/WTF/wtf/URLParser.cpp:
(WTF::URLParser::encodeNonUTF8Query):
(WTF::URLParser::copyURLPartsUntil):
(WTF::URLParser::parsedDataView):
(WTF::URLParser::domainToASCII):
(WTF::URLParser::parseHostAndPort):
* Source/WTF/wtf/cf/CFURLExtras.cpp:
(WTF::isSameOrigin):
* Source/WTF/wtf/text/StringBuilder.h:
(WTF::StringBuilder::operator StringView const):
(WTF::equal):
* Source/WTF/wtf/text/StringCommon.h:
* Source/WTF/wtf/text/StringParsingBuffer.h:
* Source/WTF/wtf/text/StringView.cpp:
(WTF::StringView::GraphemeClusters::Iterator::Impl::operator* const):
(WTF::convertASCIILowercaseAtom):
* Source/WTF/wtf/text/StringView.h:
(WTF::StringView::initialize):
(WTF::StringView::StringView):
(WTF::StringView::substring const):
(WTF::StringView::trim const):
* Source/WTF/wtf/text/TextBreakIterator.cpp:
(WTF::setTextForIterator):
* Source/WTF/wtf/text/TextBreakIterator.h:
(WTF::TextBreakIterator::setText):
(WTF::TextBreakIteratorCache::take):
(WTF::CachedTextBreakIterator::CachedTextBreakIterator):
(WTF::CachedLineBreakIteratorFactory::get):
* Source/WTF/wtf/text/cf/TextBreakIteratorCF.h:
(WTF::TextBreakIteratorCF::setText):
* Source/WTF/wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp:
(WTF::TextBreakIterator::mapModeToBackingIterator):
(WTF::TextBreakIterator::TextBreakIterator):
* Source/WTF/wtf/text/icu/TextBreakIteratorICU.h:
(WTF::TextBreakIteratorICU::TextBreakIteratorICU):
(WTF::TextBreakIteratorICU::setText):
* Source/WTF/wtf/text/icu/UTextProvider.h:
(WTF::initializeContextAwareUTextProvider):
* Source/WTF/wtf/text/icu/UTextProviderLatin1.cpp:
(WTF::openLatin1UTextProvider):
(WTF::openLatin1ContextAwareUTextProvider):
* Source/WTF/wtf/text/icu/UTextProviderLatin1.h:
* Source/WTF/wtf/text/icu/UTextProviderUTF16.cpp:
(WTF::openUTF16ContextAwareUTextProvider):
* Source/WTF/wtf/text/icu/UTextProviderUTF16.h:
* Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCCertificateGenerator.cpp:
(WebCore::LibWebRTCCertificateGenerator::RTCCertificateGeneratorCallbackWrapper::process):
* Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:
(WebCore::trimInputSample):
(WebCore::WebSocketHandshake::readStatusLine):
(WebCore::WebSocketHandshake::readHTTPHeaders):
* Source/WebCore/bindings/js/ScriptBufferSourceProvider.h:
* Source/WebCore/css/parser/CSSCustomPropertySyntax.cpp:
(WebCore::CSSCustomPropertySyntax::parseComponent):
* Source/WebCore/css/parser/CSSParserToken.cpp:
(WebCore::mergeIfAdjacent):
* Source/WebCore/editing/TextIterator.cpp:
(WebCore::WordAwareIterator::text const):
(WebCore::SearchBuffer::isWordEndMatch const):
(WebCore::SearchBuffer::isWordStartMatch const):
(WebCore::SearchBuffer::search):
* Source/WebCore/editing/TextIterator.h:
(WebCore::TextIteratorCopyableText::text const):
* Source/WebCore/editing/VisibleUnits.cpp:
(WebCore::wordBreakIteratorForMinOffsetBoundary):
(WebCore::wordBreakIteratorForMaxOffsetBoundary):
(WebCore::backwardSearchForBoundaryWithTextIterator):
(WebCore::forwardSearchForBoundaryWithTextIterator):
* Source/WebCore/html/FTPDirectoryDocument.cpp:
(WebCore::FTPDirectoryDocumentParser::append):
* Source/WebCore/html/MediaFragmentURIParser.cpp:
(WebCore::collectFraction):
* Source/WebCore/html/parser/CSSPreloadScanner.cpp:
(WebCore::CSSPreloadScanner::emitRule):
* Source/WebCore/html/parser/HTMLConstructionSite.cpp:
(WebCore::findBreakIndexSlow):
* Source/WebCore/html/parser/HTMLMetaCharsetParser.cpp:
(WebCore::HTMLMetaCharsetParser::processMeta):
* Source/WebCore/html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTTPRefreshInternal):
* Source/WebCore/html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
* Source/WebCore/html/parser/HTMLSrcsetParser.cpp:
(WebCore::appendDescriptorAndReset):
(WebCore::parseImageCandidatesFromSrcsetAttribute):
* Source/WebCore/html/track/VTTScanner.cpp:
(WebCore::VTTScanner::scanDigits):
* Source/WebCore/loader/LinkHeader.cpp:
(WebCore::parseParameterName):
* Source/WebCore/loader/ResourceCryptographicDigest.cpp:
(WebCore::parseCryptographicDigestImpl):
* Source/WebCore/page/EventSource.cpp:
(WebCore::EventSource::parseEventStreamLine):
* Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp:
(WebCore::ContentSecurityPolicySourceList::parseScheme):
(WebCore::ContentSecurityPolicySourceList::parseHost):
(WebCore::ContentSecurityPolicySourceList::parsePath):
(WebCore::ContentSecurityPolicySourceList::parsePort):
* Source/WebCore/platform/Length.cpp:
(WebCore::parseLength):
* Source/WebCore/platform/graphics/ComplexTextController.cpp:
(WebCore::ComplexTextController::offsetForPosition):
(WebCore::ComplexTextController::collectComplexTextRuns):
* Source/WebCore/platform/graphics/ComplexTextController.h:
(WebCore::ComplexTextController::ComplexTextRun::span const):
* Source/WebCore/platform/graphics/ComposedCharacterClusterTextIterator.h:
(WebCore::ComposedCharacterClusterTextIterator::ComposedCharacterClusterTextIterator):
* Source/WebCore/platform/graphics/StringTruncator.cpp:
(WebCore::stringWidth):
* Source/WebCore/platform/graphics/TextRun.h:
(WebCore::TextRun::span8):
(WebCore::TextRun::span16):
(WebCore::TextRun::setText):
* Source/WebCore/platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::advance):
* Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
(WebCore::InbandTextTrackPrivateAVF::processNativeSamples):
* Source/WebCore/platform/network/HTTPParsers.cpp:
(WebCore::trimInputSample):
(WebCore::parseHTTPHeader):
* Source/WebCore/platform/network/RFC8941.cpp:
(RFC8941::parseKey):
* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::RenderBlock::constructTextRun):
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::capitalize):
(WebCore::RenderText::previousOffset const):
(WebCore::RenderText::previousOffsetForBackwardDeletion const):
(WebCore::RenderText::nextOffset const):
(WebCore::RenderText::stringView const):
* Source/WebCore/rendering/TextPainter.cpp:
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
* Source/WebCore/svg/SVGLengthList.cpp:
(WebCore::SVGLengthList::parse):
* Source/WebCore/testing/MockCDMFactory.cpp:
(WebCore::MockCDMInstance::setServerCertificate):
* Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp:
(WebKit::readSizeFile):
* Source/WebKitLegacy/mac/Misc/WebKitNSStringExtras.mm:
(-[NSString _web_drawAtPoint:font:textColor:]):
(-[NSString _web_widthWithFont:]):
* Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WTF/TextBreakIterator.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
(TestWebKitAPI::TEST_F):
* Tools/TestWebKitAPI/Tests/WebCore/MonospaceFontTests.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp:
(TestWebKitAPI::TEST_F):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
(respondToRangeRequests):

Canonical link: https://commits.webkit.org/276616@main
  • Loading branch information
cdumez committed Mar 25, 2024
1 parent d196c00 commit 8763b25
Show file tree
Hide file tree
Showing 82 changed files with 282 additions and 279 deletions.
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/ArrayPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncToString, (JSGlobalObject* globalObject,

bool sawHoles = false;
bool genericCase = false;
JSValue result = fastJoin(globalObject, thisArray, { &comma, 1 }, length, sawHoles, genericCase);
JSValue result = fastJoin(globalObject, thisArray, span(comma), length, sawHoles, genericCase);
RETURN_IF_EXCEPTION(scope, { });

if (!sawHoles && !genericCase && result && isJSString(result) && isCoW) {
Expand Down Expand Up @@ -627,7 +627,7 @@ JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncJoin, (JSGlobalObject* globalObject, Call
unsigned unsignedLength = static_cast<unsigned>(length);
ASSERT(static_cast<double>(unsignedLength) == length);

RELEASE_AND_RETURN(scope, JSValue::encode(fastJoin(globalObject, thisObject, { &comma, 1 }, unsignedLength)));
RELEASE_AND_RETURN(scope, JSValue::encode(fastJoin(globalObject, thisObject, span(comma), unsignedLength)));
}

// 4. Let sep be ? ToString(separator).
Expand Down
6 changes: 1 addition & 5 deletions Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ String notAFunctionSourceAppender(const String& originalMessage, StringView sour
ASSERT(occurrence == ErrorInstance::FoundExactSource);
auto notAFunctionIndex = originalMessage.reverseFind("is not a function"_s);
RELEASE_ASSERT(notAFunctionIndex != notFound);
StringView displayValue;
if (originalMessage.is8Bit())
displayValue = StringView(originalMessage.characters8(), notAFunctionIndex - 1);
else
displayValue = StringView(originalMessage.characters16(), notAFunctionIndex - 1);
auto displayValue = StringView { originalMessage }.left(notAFunctionIndex - 1);

StringView base = functionCallBase(sourceText);
if (!base)
Expand Down
6 changes: 3 additions & 3 deletions Source/JavaScriptCore/runtime/ISO8601.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static std::optional<Duration> parseDuration(StringParsingBuffer<CharacterType>&
while (digits < buffer.lengthRemaining() && isASCIIDigit(buffer[digits]))
digits++;

double integer = factor * parseInt({ buffer.position(), digits }, 10);
double integer = factor * parseInt(buffer.span().first(digits), 10);
buffer.advanceBy(digits);
if (buffer.atEnd())
return std::nullopt;
Expand Down Expand Up @@ -186,7 +186,7 @@ static std::optional<Duration> parseDuration(StringParsingBuffer<CharacterType>&
while (digits < buffer.lengthRemaining() && isASCIIDigit(buffer[digits]))
digits++;

double integer = factor * parseInt({ buffer.position(), digits }, 10);
double integer = factor * parseInt(buffer.span().first(digits), 10);
buffer.advanceBy(digits);
if (buffer.atEnd())
return std::nullopt;
Expand All @@ -200,7 +200,7 @@ static std::optional<Duration> parseDuration(StringParsingBuffer<CharacterType>&
if (!digits || digits > 9)
return std::nullopt;

fractionalPart = { buffer.position(), digits };
fractionalPart = buffer.span().first(digits);
buffer.advanceBy(digits);
if (buffer.atEnd())
return std::nullopt;
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/IntlCollator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void IntlCollator::checkICULocaleInvariants(const LocaleSet& locales)
ASSERT(U_SUCCESS(status));
auto resultJSC = compareASCIIWithUCADUCET(xstring, 1, ystring, 1);
if (resultJSC && resultICU != resultJSC.value()) {
dataLogLn("BAD ", locale, " ", makeString(hex(x)), "(", StringView(xstring, 1), ") <=> ", makeString(hex(y)), "(", StringView(ystring, 1), ") ICU:(", static_cast<int32_t>(resultICU), "),JSC:(", static_cast<int32_t>(resultJSC.value()), ")");
dataLogLn("BAD ", locale, " ", makeString(hex(x)), "(", StringView { span(*xstring) }, ") <=> ", makeString(hex(y)), "(", StringView { span(*ystring) }, ") ICU:(", static_cast<int32_t>(resultICU), "),JSC:(", static_cast<int32_t>(resultJSC.value()), ")");
allAreGood = false;
}
}
Expand Down Expand Up @@ -498,7 +498,7 @@ void IntlCollator::checkICULocaleInvariants(const LocaleSet& locales)
CRASH();
}
} else {
if (StringView(buffer.data(), buffer.size()).containsOnlyASCII()) {
if (charactersAreAllASCII(buffer.span())) {
dataLogLn("BAD ", locale, " ", String(buffer.data(), buffer.size()), " including ASCII tailored characters");
CRASH();
}
Expand Down
10 changes: 5 additions & 5 deletions Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static String canonicalizeTimeZoneName(const String& timeZoneName)
if (!ianaTimeZone)
break;

StringView ianaTimeZoneView(ianaTimeZone, ianaTimeZoneLength);
StringView ianaTimeZoneView(std::span(ianaTimeZone, ianaTimeZoneLength));
if (!equalIgnoringASCIICase(timeZoneName, ianaTimeZoneView))
continue;

Expand Down Expand Up @@ -888,7 +888,7 @@ void IntlDateTimeFormat::initializeDateTimeFormat(JSGlobalObject* globalObject,
return;
}
replaceHourCycleInSkeleton(skeleton, specifiedHour12);
dataLogLnIf(IntlDateTimeFormatInternal::verbose, "replaced:(", StringView(skeleton.data(), skeleton.size()), ")");
dataLogLnIf(IntlDateTimeFormatInternal::verbose, "replaced:(", StringView { skeleton.span() }, ")");

patternBuffer = vm.intlCache().getBestDateTimePattern(dataLocaleWithExtensions, skeleton.data(), skeleton.size(), status);
if (U_FAILURE(status)) {
Expand Down Expand Up @@ -940,7 +940,7 @@ void IntlDateTimeFormat::initializeDateTimeFormat(JSGlobalObject* globalObject,
if (hourCycle != HourCycle::None)
replaceHourCycleInPattern(patternBuffer, hourCycle);

StringView pattern(patternBuffer.data(), patternBuffer.size());
StringView pattern(patternBuffer.span());
setFormatsFromPattern(pattern);

dataLogLnIf(IntlDateTimeFormatInternal::verbose, "locale:(", m_locale, "),dataLocale:(", dataLocaleWithExtensions, "),pattern:(", pattern, ")");
Expand Down Expand Up @@ -1356,7 +1356,7 @@ JSValue IntlDateTimeFormat::formatToParts(JSGlobalObject* globalObject, double v
if (!parts)
return throwOutOfMemoryError(globalObject, scope);

StringView resultStringView(result.data(), result.size());
StringView resultStringView(result.span());
auto literalString = jsNontrivialString(vm, "literal"_s);

int32_t resultLength = result.size();
Expand Down Expand Up @@ -1697,7 +1697,7 @@ JSValue IntlDateTimeFormat::formatRangeToParts(JSGlobalObject* globalObject, dou
Vector<UChar, 32> buffer(std::span<const UChar> { formattedStringPointer, static_cast<size_t>(formattedStringLength) });
replaceNarrowNoBreakSpaceOrThinSpaceWithNormalSpace(buffer);

StringView resultStringView(buffer.data(), buffer.size());
StringView resultStringView(buffer.span());

// We care multiple categories (UFIELD_CATEGORY_DATE and UFIELD_CATEGORY_DATE_INTERVAL_SPAN).
// So we do not constraint iterator.
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/IntlDurationFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ JSValue IntlDurationFormat::formatToParts(JSGlobalObject* globalObject, ISO8601:
const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status);
if (U_FAILURE(status))
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
StringView resultStringView(formattedStringPointer, formattedStringLength);
StringView resultStringView(std::span(formattedStringPointer, formattedStringLength));

auto iterator = std::unique_ptr<UConstrainedFieldPosition, ICUDeleter<ucfpos_close>>(ucfpos_open(&status));
if (U_FAILURE(status))
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/IntlListFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ JSValue IntlListFormat::formatToParts(JSGlobalObject* globalObject, JSValue list
const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status);
if (U_FAILURE(status))
return throwTypeError(globalObject, scope, "failed to format list of strings"_s);
StringView resultStringView(formattedStringPointer, formattedStringLength);
StringView resultStringView(std::span(formattedStringPointer, formattedStringLength));

auto iterator = std::unique_ptr<UConstrainedFieldPosition, ICUDeleter<ucfpos_close>>(ucfpos_open(&status));
if (U_FAILURE(status))
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/IntlLocale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ JSArray* IntlLocale::hourCycles(JSGlobalObject* globalObject)
return nullptr;
}

dataLogLnIf(IntlLocaleInternal::verbose, "pattern:(", StringView(pattern.data(), pattern.size()), ")");
dataLogLnIf(IntlLocaleInternal::verbose, "pattern:(", StringView { pattern.span() }, ")");

switch (IntlDateTimeFormat::hourCycleFromPattern(pattern)) {
case IntlDateTimeFormat::HourCycle::None:
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/IntlNumberFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ void IntlNumberFormat::formatRangeToPartsInternal(JSGlobalObject* globalObject,
throwTypeError(globalObject, scope, "Failed to format number range"_s);
return;
}
StringView resultStringView(formattedStringPointer, formattedStringLength);
StringView resultStringView(std::span(formattedStringPointer, formattedStringLength));

// We care multiple categories (UFIELD_CATEGORY_DATE and UFIELD_CATEGORY_DATE_INTERVAL_SPAN).
// So we do not constraint iterator.
Expand Down
12 changes: 3 additions & 9 deletions Source/JavaScriptCore/runtime/JSString.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,8 @@ ALWAYS_INLINE StringView JSRopeString::unsafeView(JSGlobalObject* globalObject)
{
if constexpr (validateDFGDoesGC)
vm().verifyCanGC();
if (isSubstring()) {
auto& base = substringBase()->valueInternal();
if (base.is8Bit())
return StringView(base.characters8() + substringOffset(), length());
return StringView(base.characters16() + substringOffset(), length());
}
if (isSubstring())
return StringView { substringBase()->valueInternal() }.substring(substringOffset(), length());
return resolveRope(globalObject);
}

Expand All @@ -1112,9 +1108,7 @@ ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingStr
vm().verifyCanGC();
if (isSubstring()) {
auto& base = substringBase()->valueInternal();
if (base.is8Bit())
return { { base.characters8() + substringOffset(), length() }, base };
return { { base.characters16() + substringOffset(), length() }, base };
return { StringView { base }.substring(substringOffset(), length()), base };
}
auto& string = resolveRope(globalObject);
return { string, string };
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/LiteralParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ ALWAYS_INLINE TokenType LiteralParser<CharType>::Lexer::lex(LiteralParserToken<C
return tokenType;
}
}
m_lexErrorMessage = makeString("Unrecognized token '"_s, StringView { m_ptr, 1 }, '\'');
m_lexErrorMessage = makeString("Unrecognized token '"_s, span(*m_ptr), '\'');
return TokError;
}

Expand Down Expand Up @@ -952,7 +952,7 @@ TokenType LiteralParser<CharType>::Lexer::lexStringSlow(LiteralParserToken<CharT
} // uNNNN == 5 characters
for (int i = 1; i < 5; i++) {
if (!isASCIIHexDigit(m_ptr[i])) {
m_lexErrorMessage = makeString("\"\\"_s, StringView { m_ptr, 5 }, "\" is not a valid unicode escape"_s);
m_lexErrorMessage = makeString("\"\\"_s, std::span { m_ptr, 5 }, "\" is not a valid unicode escape"_s);
return TokError;
}
}
Expand All @@ -966,7 +966,7 @@ TokenType LiteralParser<CharType>::Lexer::lexStringSlow(LiteralParserToken<CharT
m_ptr++;
break;
}
m_lexErrorMessage = makeString("Invalid escape character "_s, StringView { m_ptr, 1 });
m_lexErrorMessage = makeString("Invalid escape character "_s, span(*m_ptr));
return TokError;
}
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ ALWAYS_INLINE JSValue LiteralParser<CharType>::parsePrimitiveValue(VM& vm)

auto tryMakeErrorString = [&] (unsigned length) -> String {
bool addEllipsis = length != token->stringOrIdentifierLength;
return tryMakeString("Unexpected identifier \""_s, StringView { token->identifierStart, length }, addEllipsis ? "..."_s : ""_s, '"');
return tryMakeString("Unexpected identifier \""_s, std::span { token->identifierStart, length }, addEllipsis ? "..."_s : ""_s, '"');
};

constexpr unsigned maxLength = 200;
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/wasm/WasmIndexOrName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ String makeString(const IndexOrName& ion)
const String moduleName = ion.nameSection()->moduleName.size() ? String(ion.nameSection()->moduleName.data(), ion.nameSection()->moduleName.size()) : String(ion.nameSection()->moduleHash.data(), ion.nameSection()->moduleHash.size());
if (ion.isIndex())
return makeString(moduleName, ".wasm-function["_s, ion.index(), ']');
return makeString(moduleName, ".wasm-function["_s, StringView(ion.name()->data(), ion.name()->size()), ']');
return makeString(moduleName, ".wasm-function["_s, ion.name()->span(), ']');
}

} } // namespace JSC::Wasm
2 changes: 1 addition & 1 deletion Source/WTF/wtf/HexNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::pair<LChar*, unsigned> appendHex(LChar* buffer, unsigned bufferSize, std::u

void printInternal(PrintStream& out, HexNumberBuffer buffer)
{
out.print(StringView(buffer.characters(), buffer.length));
out.print(StringView(buffer.span()));
}

} // namespace WTF
1 change: 1 addition & 0 deletions Source/WTF/wtf/HexNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct HexNumberBuffer {
unsigned length;

const LChar* characters() const { return &*(buffer.end() - length); }
std::span<const LChar> span() const { return { characters(), length }; }
};

template<typename NumberType> HexNumberBuffer hex(NumberType number, unsigned minimumDigits = 0, HexConversionMode mode = Uppercase)
Expand Down
4 changes: 2 additions & 2 deletions Source/WTF/wtf/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void URL::setHost(StringView newHost)
parse(makeString(
StringView(m_string).left(hostStart()),
slashSlashNeeded ? "//"_s : ""_s,
hasSpecialScheme() ? StringView(encodedHostName.data(), encodedHostName.size()) : newHost,
hasSpecialScheme() ? StringView(encodedHostName.span()) : newHost,
StringView(m_string).substring(m_hostEnd)
));
}
Expand Down Expand Up @@ -550,7 +550,7 @@ void URL::setHostAndPort(StringView hostAndPort)
parse(makeString(
StringView(m_string).left(hostStart()),
slashSlashNeeded ? "//"_s : ""_s,
hasSpecialScheme() ? StringView(encodedHostName.data(), encodedHostName.size()) : hostName,
hasSpecialScheme() ? StringView(encodedHostName.span()) : hostName,
portString.isEmpty() ? ""_s : ":"_s,
portString,
StringView(m_string).substring(pathStart())
Expand Down
10 changes: 5 additions & 5 deletions Source/WTF/wtf/URLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ ALWAYS_INLINE void URLParser::utf8QueryEncode(const CodePointIterator<CharacterT
template<typename CharacterType>
void URLParser::encodeNonUTF8Query(const Vector<UChar>& source, const URLTextEncoding& encoding, CodePointIterator<CharacterType> iterator)
{
auto encoded = encoding.encodeForURLParsing(StringView(source.data(), source.size()));
auto encoded = encoding.encodeForURLParsing(source.span());
auto* data = encoded.data();
size_t length = encoded.size();

Expand Down Expand Up @@ -838,7 +838,7 @@ void URLParser::copyURLPartsUntil(const URL& base, URLPart part, const CodePoint
m_url.m_schemeEnd = base.m_schemeEnd;
}

switch (scheme(StringView(m_asciiBuffer.data(), m_url.m_schemeEnd))) {
switch (scheme(m_asciiBuffer.subspan(0, m_url.m_schemeEnd))) {
case Scheme::WS:
case Scheme::WSS:
nonUTF8QueryEncoding = nullptr;
Expand Down Expand Up @@ -1060,7 +1060,7 @@ ALWAYS_INLINE StringView URLParser::parsedDataView(size_t start, size_t length)
{
if (UNLIKELY(m_didSeeSyntaxViolation)) {
ASSERT(start + length <= m_asciiBuffer.size());
return StringView(m_asciiBuffer.data() + start, length);
return m_asciiBuffer.subspan(start, length);
}
ASSERT(start + length <= m_inputString.length());
return StringView(m_inputString).substring(start, length);
Expand Down Expand Up @@ -2576,7 +2576,7 @@ template<typename CharacterType> std::optional<URLParser::LCharBuffer> URLParser
UNUSED_PARAM(numCharactersConverted);
#endif // ASSERT_ENABLED
ascii.append(std::span { hostnameBuffer, numCharactersConverted });
if (domain != StringView(ascii.data(), ascii.size()))
if (domain != StringView(ascii.span()))
syntaxViolation(iteratorForSyntaxViolationPosition);
return ascii;
}
Expand Down Expand Up @@ -2856,7 +2856,7 @@ auto URLParser::parseHostAndPort(CodePointIterator<CharacterType> iterator) -> H
String domain = String::fromUTF8(percentDecoded.data(), percentDecoded.size());
if (domain.isNull())
return HostParsingResult::InvalidHost;
if (domain != StringView(percentDecoded.data(), percentDecoded.size()))
if (domain != StringView(percentDecoded.span()))
syntaxViolation(hostBegin);
auto asciiDomain = domainToASCII(*domain.impl(), hostBegin);
if (!asciiDomain || hasForbiddenHostCodePoint(asciiDomain.value()))
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/cf/CFURLExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool isSameOrigin(CFURLRef a, const URL& b)
auto aBytes = bytesAsVector(a);
RELEASE_ASSERT(aBytes.size() <= String::MaxLength);

StringView aString { aBytes.data(), static_cast<unsigned>(aBytes.size()) };
StringView aString { aBytes.span() };
StringView bString { b.string() };

if (!b.hasPath())
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/NullTextBreakIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NullTextBreakIterator {
return false;
}

void setText(StringView, const UChar*, unsigned)
void setText(StringView, std::span<const UChar>)
{
ASSERT_NOT_REACHED();
}
Expand Down
6 changes: 3 additions & 3 deletions Source/WTF/wtf/text/StringBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ inline void StringBuilder::swap(StringBuilder& other)
inline StringBuilder::operator StringView() const
{
if (is8Bit())
return { characters<LChar>(), length() };
return { characters<UChar>(), length() };
return span<LChar>();
return span<UChar>();
}

inline void StringBuilder::append(UChar character)
Expand Down Expand Up @@ -320,7 +320,7 @@ template<typename... StringTypes> void StringBuilder::append(StringTypes... stri

template<typename CharacterType> bool equal(const StringBuilder& builder, const CharacterType* buffer, unsigned length)
{
return builder == StringView { buffer, length };
return builder == StringView { std::span { buffer, length } };
}

template<> struct IntegerToStringConversionTrait<StringBuilder> {
Expand Down
11 changes: 11 additions & 0 deletions Source/WTF/wtf/text/StringCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,19 @@ inline void copyElements(LChar* __restrict destination, const UChar* __restrict
copyElements(bitwise_cast<uint8_t*>(destination), bitwise_cast<const uint16_t*>(source), length);
}

inline std::span<const LChar> span(const LChar& character)
{
return { &character, 1 };
}

inline std::span<const UChar> span(const UChar& character)
{
return { &character, 1 };
}

}

using WTF::equalIgnoringASCIICase;
using WTF::equalLettersIgnoringASCIICase;
using WTF::isLatin1;
using WTF::span;
4 changes: 3 additions & 1 deletion Source/WTF/wtf/text/StringParsingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class StringParsingBuffer final {
m_position = position;
}

StringView stringViewOfCharactersRemaining() const { return { m_position, lengthRemaining() }; }
StringView stringViewOfCharactersRemaining() const { return span(); }

CharacterType consume()
{
Expand All @@ -77,6 +77,8 @@ class StringParsingBuffer final {
return character;
}

std::span<const CharacterType> span() const { return { m_position, lengthRemaining() }; }

std::span<const CharacterType> consume(size_t count)
{
ASSERT(count <= lengthRemaining());
Expand Down
Loading

0 comments on commit 8763b25

Please sign in to comment.