Skip to content

Commit

Permalink
Simplify code by using std::span more
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271338

Reviewed by Darin Adler.

* Source/JavaScriptCore/runtime/GenericTypedArrayView.h:
* Source/WTF/wtf/Algorithms.h:
(WTF::spanReinterpretCast): Deleted.
* Source/WTF/wtf/StdLibExtras.h:
(WTF::spanReinterpretCast):
* Source/WebCore/Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::take):
* Source/WebCore/Modules/fetch/FormDataConsumer.cpp:
(WebCore::FormDataConsumer::consumeBlob):
* Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp:
(WebCore::RTCEncodedFrame::rtcFrame):
* Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp:
(WebCore::RTCRtpSFrameTransform::createStreams):
* Source/WebCore/Modules/websockets/WebSocketDeflater.cpp:
(WebCore::WebSocketInflater::finish):
* Source/WebCore/Modules/webtransport/DatagramSink.cpp:
(WebCore::DatagramSink::write):
* Source/WebCore/bindings/js/BufferSource.h:
(WebCore::toBufferSource):
* Source/WebCore/dom/DocumentParser.h:
(WebCore::DocumentParser::appendBytes):
* Source/WebCore/dom/TextEncoder.cpp:
(WebCore::TextEncoder::encode const):
* Source/WebCore/fileapi/NetworkSendQueue.cpp:
(WebCore::NetworkSendQueue::enqueue):
(WebCore::NetworkSendQueue::processMessages):
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::bufferData):
(WebCore::WebGLRenderingContextBase::bufferSubData):
(WebCore::WebGLRenderingContextBase::compressedTexImage2D):
(WebCore::WebGLRenderingContextBase::compressedTexSubImage2D):
(WebCore::WebGLRenderingContextBase::validateTexFuncData):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp:
(WebCore::HTMLFastPathParser::scanTagName):
* Source/WebCore/loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::replaceDocumentWithResultOfExecutingJavascriptURL):
* Source/WebCore/platform/SharedBuffer.cpp:
(WebCore::FragmentedSharedBuffer::toIPCData const):
* Source/WebCore/platform/SharedBufferChunkReader.cpp:
(WebCore::SharedBufferChunkReader::nextChunk):
(WebCore::SharedBufferChunkReader::peek):
* Source/WebCore/platform/SharedMemory.h:
(WebCore::SharedMemory::bytes const):
* Source/WebCore/platform/WebCorePersistentCoders.cpp:
(WTF::Persistence::encodeCFData):
* Source/WebCore/platform/generic/KeyedEncoderGeneric.cpp:
(WebCore::KeyedEncoderGeneric::encodeString):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(WebCore::CDMSessionAVContentKeySession::releaseKeys):
(WebCore::CDMSessionAVContentKeySession::update):
(WebCore::CDMSessionAVContentKeySession::generateKeyReleaseMessage):
* Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
* Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
(-[WebAVAssetWriterDelegate assetWriter:didProduceFragmentedHeaderData:]):
(-[WebAVAssetWriterDelegate assetWriter:didProduceFragmentedMediaData:fragmentedMediaDataReport:]):
(WebCore::MediaRecorderPrivateWriter::appendData):
* Source/WebKit/NetworkProcess/cocoa/WKURLSessionTaskDelegate.mm:
(-[WKURLSessionTaskDelegate URLSession:dataTask:didReceiveData:]):
* Source/WebKit/Shared/WebCompiledContentRuleList.cpp:
(WebKit::WebCompiledContentRuleList::spanWithOffsetAndLength const):
* Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(-[WKBrowsingContextController loadHTMLString:baseURL:userData:]):
(-[WKBrowsingContextController loadData:MIMEType:textEncodingName:baseURL:userData:]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadData:MIMEType:characterEncodingName:baseURL:]):
(-[WKWebView loadSimulatedRequest:response:responseData:]):
(-[WKWebView _loadData:MIMEType:characterEncodingName:baseURL:userData:]):
* Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
(produceClientDataJson):
(+[_WKWebAuthenticationPanel convertToCoreCreationOptionsWithOptions:]):
(+[_WKWebAuthenticationPanel convertToCoreRequestOptionsWithOptions:]):
(asUInt8Span): Deleted.
* Source/WebKit/UIProcess/Cocoa/SOAuthorization/RedirectSOAuthorizationSession.mm:
(WebKit::RedirectSOAuthorizationSession::completeInternal):
(WebKit::span): Deleted.
* Source/WebKit/UIProcess/Cocoa/SessionStateCoding.mm:
(WebKit::decodeSessionState):
(WebKit::span): Deleted.
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::insertMultiRepresentationHEIC):
(WebKit::span): Deleted.
* Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
(WebKit::LocalAuthenticatorInternal::toArrayBuffer):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadServiceWorker):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView removeBackgroundMenu]):
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxyFunctionsGenerated.cpp:
(WebKit::RemoteGraphicsContextGLProxy::bufferData):
(WebKit::RemoteGraphicsContextGLProxy::bufferSubData):
(WebKit::RemoteGraphicsContextGLProxy::texImage2D):
(WebKit::RemoteGraphicsContextGLProxy::texSubImage2D):
(WebKit::RemoteGraphicsContextGLProxy::compressedTexImage2D):
(WebKit::RemoteGraphicsContextGLProxy::compressedTexSubImage2D):
(WebKit::RemoteGraphicsContextGLProxy::texImage3D):
(WebKit::RemoteGraphicsContextGLProxy::texSubImage3D):
(WebKit::RemoteGraphicsContextGLProxy::compressedTexImage3D):
(WebKit::RemoteGraphicsContextGLProxy::compressedTexSubImage3D):
* Source/WebKit/WebProcess/Network/WebTransportSendStreamSink.cpp:
(WebKit::WebTransportSendStreamSink::write):
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::relayAccessibilityNotification):

Canonical link: https://commits.webkit.org/276479@main
  • Loading branch information
cdumez committed Mar 21, 2024
1 parent 30c07bf commit c448798
Show file tree
Hide file tree
Showing 45 changed files with 98 additions and 123 deletions.
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/runtime/GenericTypedArrayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class GenericTypedArrayView final : public ArrayBufferView {
public:
static Ref<GenericTypedArrayView> create(size_t length);
static Ref<GenericTypedArrayView> create(const typename Adaptor::Type* array, size_t length);
static Ref<GenericTypedArrayView> create(std::span<const typename Adaptor::Type> data) { return create(data.data(), data.size()); }
static Ref<GenericTypedArrayView> create(RefPtr<ArrayBuffer>&&, size_t byteOffset, std::optional<size_t> length);
static RefPtr<GenericTypedArrayView> tryCreate(size_t length);
static RefPtr<GenericTypedArrayView> tryCreate(const typename Adaptor::Type* array, size_t length);
static RefPtr<GenericTypedArrayView> tryCreate(std::span<const typename Adaptor::Type> data) { return tryCreate(data.data(), data.size()); }
static RefPtr<GenericTypedArrayView> tryCreate(RefPtr<ArrayBuffer>&&, size_t byteOffset, std::optional<size_t> length);

static Ref<GenericTypedArrayView> createUninitialized(size_t length);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/fetch/FetchBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ FetchBody::TakenData FetchBody::take()
return SharedBuffer::create(PAL::TextCodecUTF8::encodeUTF8(urlSearchParamsBody().toString()));

if (isArrayBuffer())
return SharedBuffer::create(static_cast<const char*>(arrayBufferBody().data()), arrayBufferBody().byteLength());
return SharedBuffer::create(arrayBufferBody().bytes());
if (isArrayBufferView())
return SharedBuffer::create(static_cast<const uint8_t*>(arrayBufferViewBody().baseAddress()), arrayBufferViewBody().byteLength());
return SharedBuffer::create(arrayBufferViewBody().bytes());

return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FormDataConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void FormDataConsumer::consumeBlob(const URL& blobURL)
}

if (auto data = loader->arrayBufferResult())
weakThis->consume(std::span { static_cast<const uint8_t*>(data->data()), data->byteLength() });
weakThis->consume(data->bytes());
});

m_blobLoader->start(blobURL, m_context.get(), FileReaderLoader::ReadAsArrayBuffer);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void RTCEncodedFrame::setData(JSC::ArrayBuffer& buffer)
Ref<RTCRtpTransformableFrame> RTCEncodedFrame::rtcFrame()
{
if (m_data) {
m_frame->setData({ static_cast<const uint8_t*>(m_data->data()), m_data->byteLength() });
m_frame->setData(m_data->bytes());
m_data = nullptr;
}
return m_frame;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ ExceptionOr<void> RTCRtpSFrameTransform::createStreams()
}, [&](RefPtr<RTCEncodedVideoFrame>& value) {
transformFrame(*value, globalObject, transformer.get(), *readableStreamSource, context.identifier(), weakThis);
}, [&](RefPtr<ArrayBuffer>& value) {
transformFrame({ static_cast<const uint8_t*>(value->data()), value->byteLength() }, globalObject, transformer.get(), *readableStreamSource, context.identifier(), weakThis);
transformFrame(value->bytes(), globalObject, transformer.get(), *readableStreamSource, context.identifier(), weakThis);
}, [&](RefPtr<ArrayBufferView>& value) {
transformFrame({ static_cast<const uint8_t*>(value->data()), value->byteLength() }, globalObject, transformer.get(), *readableStreamSource, context.identifier(), weakThis);
transformFrame(value->bytes(), globalObject, transformer.get(), *readableStreamSource, context.identifier(), weakThis);
});
return { };
}));
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/websockets/WebSocketDeflater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool WebSocketInflater::finish()
m_buffer.grow(bufferSize.value());
size_t availableCapacity = m_buffer.size() - writePosition;
size_t remainingLength = strippedFields.size() - consumedSoFar;
setStreamParameter(m_stream.get(), std::span { strippedFields.data() + consumedSoFar, remainingLength }, m_buffer.data() + writePosition, availableCapacity);
setStreamParameter(m_stream.get(), std::span { strippedFields }.subspan(consumedSoFar), m_buffer.data() + writePosition, availableCapacity);
int result = inflate(m_stream.get(), Z_FINISH);
consumedSoFar += remainingLength - m_stream->avail_in;
m_buffer.shrink(writePosition + availableCapacity - m_stream->avail_out);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/webtransport/DatagramSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void DatagramSink::write(ScriptExecutionContext& context, JSC::JSValue value, DO
return promise.settle(Exception { ExceptionCode::ExistingExceptionError });

WTF::switchOn(arrayBufferOrView, [&](auto& arrayBufferOrView) {
send({ static_cast<const uint8_t*>(arrayBufferOrView->data()), arrayBufferOrView->byteLength() }, [promise = WTFMove(promise)] () mutable {
send(arrayBufferOrView->bytes(), [promise = WTFMove(promise)] () mutable {
// FIXME: Reject if sending failed.
promise.resolve();
});
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/bindings/js/BufferSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <wtf/RefPtr.h>

#if PLATFORM(COCOA) && defined(__OBJC__)
#include <wtf/cocoa/SpanCocoa.h>
OBJC_CLASS NSData;
#endif

Expand Down Expand Up @@ -86,7 +87,7 @@ inline BufferSource toBufferSource(const uint8_t* data, size_t length)
#if PLATFORM(COCOA) && defined(__OBJC__)
inline BufferSource toBufferSource(NSData *data)
{
return BufferSource(JSC::ArrayBuffer::tryCreate(static_cast<const uint8_t*>(data.bytes), data.length));
return BufferSource(JSC::ArrayBuffer::tryCreate(toSpan(data)));
}

inline RetainPtr<NSData> toNSData(const BufferSource& data)
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/dom/DecodedDataDocumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ DecodedDataDocumentParser::DecodedDataDocumentParser(Document& document)
{
}

void DecodedDataDocumentParser::appendBytes(DocumentWriter& writer, const uint8_t* data, size_t length)
void DecodedDataDocumentParser::appendBytes(DocumentWriter& writer, std::span<const uint8_t> data)
{
if (!length)
if (data.empty())
return;

String decoded = writer.decoder().decode(data, length);
String decoded = writer.decoder().decode(data);
if (decoded.isEmpty())
return;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/DecodedDataDocumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DecodedDataDocumentParser : public DocumentParser {
void append(RefPtr<StringImpl>&&) override = 0;

// appendBytes and flush are used by DocumentWriter (the loader).
void appendBytes(DocumentWriter&, const uint8_t* bytes, size_t length) override;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) override;
void flush(DocumentWriter&) override;
};

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/DocumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DocumentParser : public RefCounted<DocumentParser> {
virtual void insert(SegmentedString&&) = 0;

// appendBytes and flush are used by DocumentWriter (the loader).
virtual void appendBytes(DocumentWriter&, const uint8_t* bytes, size_t length) = 0;
virtual void appendBytes(DocumentWriter&, std::span<const uint8_t>) = 0;
virtual void flush(DocumentWriter&) = 0;

virtual void append(RefPtr<StringImpl>&&) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/RawDataDocumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RawDataDocumentParser : public DocumentParser {
void flush(DocumentWriter& writer) override
{
// Make sure appendBytes is called at least once.
appendBytes(writer, nullptr, 0);
appendBytes(writer, { });
}

void insert(SegmentedString&&) override
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/dom/TextEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <JavaScriptCore/GenericTypedArrayViewInlines.h>
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/JSGenericTypedArrayViewInlines.h>
#include <wtf/Algorithms.h>

namespace WebCore {

Expand All @@ -39,7 +40,7 @@ String TextEncoder::encoding() const
RefPtr<Uint8Array> TextEncoder::encode(String&& input) const
{
auto result = input.tryGetUTF8([&](std::span<const char> span) -> RefPtr<Uint8Array> {
return Uint8Array::tryCreate(reinterpret_cast<const uint8_t*>(span.data()), span.size());
return Uint8Array::tryCreate(spanReinterpretCast<const uint8_t>(span));
});
if (result)
return result.value();
Expand Down
7 changes: 3 additions & 4 deletions Source/WebCore/fileapi/NetworkSendQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ void NetworkSendQueue::enqueue(CString&& utf8)
void NetworkSendQueue::enqueue(const JSC::ArrayBuffer& binaryData, unsigned byteOffset, unsigned byteLength)
{
if (m_queue.isEmpty()) {
auto* data = static_cast<const uint8_t*>(binaryData.data());
m_writeRawData(std::span(data + byteOffset, byteLength));
m_writeRawData(binaryData.bytes().subspan(byteOffset, byteLength));
return;
}
m_queue.append(SharedBuffer::create(static_cast<const uint8_t*>(binaryData.data()) + byteOffset, byteLength));
m_queue.append(SharedBuffer::create(binaryData.bytes().subspan(byteOffset, byteLength)));
}

void NetworkSendQueue::enqueue(WebCore::Blob& blob)
Expand Down Expand Up @@ -104,7 +103,7 @@ void NetworkSendQueue::processMessages()
}

if (const auto& result = loader->arrayBufferResult()) {
m_writeRawData(std::span(static_cast<const uint8_t*>(result->data()), result->byteLength()));
m_writeRawData(result->bytes());
return;
}
ASSERT(errorCode);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/ImageDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ImageDocumentParser final : public RawDataDocumentParser {

ImageDocument& document() const;

void appendBytes(DocumentWriter&, const uint8_t*, size_t) override;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) override;
void finish() override;
};

Expand Down Expand Up @@ -198,7 +198,7 @@ inline ImageDocument& ImageDocumentParser::document() const
return downcast<ImageDocument>(*RawDataDocumentParser::document());
}

void ImageDocumentParser::appendBytes(DocumentWriter&, const uint8_t*, size_t)
void ImageDocumentParser::appendBytes(DocumentWriter&, std::span<const uint8_t>)
{
document().updateDuringParsing();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/MediaDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MediaDocumentParser final : public RawDataDocumentParser {
{
}

void appendBytes(DocumentWriter&, const uint8_t*, size_t) final;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) final;
void createDocumentStructure();

WeakPtr<HTMLMediaElement> m_mediaElement;
Expand Down Expand Up @@ -129,7 +129,7 @@ void MediaDocumentParser::createDocumentStructure()
frame->checkedLoader()->setOutgoingReferrer(document->completeURL(m_outgoingReferrer));
}

void MediaDocumentParser::appendBytes(DocumentWriter&, const uint8_t*, size_t)
void MediaDocumentParser::appendBytes(DocumentWriter&, std::span<const uint8_t>)
{
if (m_mediaElement)
return;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/ModelDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ModelDocumentParser final : public RawDataDocumentParser {

void createDocumentStructure();

void appendBytes(DocumentWriter&, const uint8_t*, size_t) final;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) final;
void finish() final;

WeakPtr<HTMLModelElement, WeakPtrImplWithEventTargetData> m_modelElement;
Expand Down Expand Up @@ -126,7 +126,7 @@ void ModelDocumentParser::createDocumentStructure()
frame->loader().setOutgoingReferrer(document.completeURL(m_outgoingReferrer));
}

void ModelDocumentParser::appendBytes(DocumentWriter&, const uint8_t*, size_t)
void ModelDocumentParser::appendBytes(DocumentWriter&, std::span<const uint8_t>)
{
if (!m_modelElement)
createDocumentStructure();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/PDFDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PDFDocumentParser final : public RawDataDocumentParser {

PDFDocument& document() const;

void appendBytes(DocumentWriter&, const uint8_t*, size_t) override;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) override;
void finish() override;
};

Expand All @@ -82,7 +82,7 @@ inline PDFDocument& PDFDocumentParser::document() const
return downcast<PDFDocument>(*RawDataDocumentParser::document());
}

void PDFDocumentParser::appendBytes(DocumentWriter&, const uint8_t*, size_t)
void PDFDocumentParser::appendBytes(DocumentWriter&, std::span<const uint8_t>)
{
document().updateDuringParsing();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/PluginDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PluginDocumentParser final : public RawDataDocumentParser {
{
}

void appendBytes(DocumentWriter&, const uint8_t*, size_t) final;
void appendBytes(DocumentWriter&, std::span<const uint8_t>) final;
void createDocumentStructure();
static Ref<HTMLStyleElement> createStyleElement(Document&);

Expand Down Expand Up @@ -126,7 +126,7 @@ void PluginDocumentParser::createDocumentStructure()
document.setHasVisuallyNonEmptyCustomContent();
}

void PluginDocumentParser::appendBytes(DocumentWriter&, const uint8_t*, size_t)
void PluginDocumentParser::appendBytes(DocumentWriter&, std::span<const uint8_t>)
{
if (m_embedElement)
return;
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ void WebGLRenderingContextBase::bufferData(GCGLenum target, std::optional<Buffer
return;

std::visit([&](auto& data) {
m_context->bufferData(target, std::span(static_cast<const uint8_t*>(data->data()), data->byteLength()), usage);
m_context->bufferData(target, data->bytes(), usage);
}, data.value());
}

Expand All @@ -1161,7 +1161,7 @@ void WebGLRenderingContextBase::bufferSubData(GCGLenum target, long long offset,
}

std::visit([&](auto& data) {
m_context->bufferSubData(target, static_cast<GCGLintptr>(offset), std::span(static_cast<const uint8_t*>(data->data()), data->byteLength()));
m_context->bufferSubData(target, static_cast<GCGLintptr>(offset), data->bytes());
}, data);
}

Expand Down Expand Up @@ -1248,7 +1248,7 @@ void WebGLRenderingContextBase::compressedTexImage2D(GCGLenum target, GCGLint le
return;
if (!validateCompressedTexFormat("compressedTexImage2D", internalformat))
return;
m_context->compressedTexImage2D(target, level, internalformat, width, height, border, data.byteLength(), std::span(static_cast<const uint8_t*>(data.baseAddress()), data.byteLength()));
m_context->compressedTexImage2D(target, level, internalformat, width, height, border, data.byteLength(), data.bytes());
}

void WebGLRenderingContextBase::compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, ArrayBufferView& data)
Expand All @@ -1259,7 +1259,7 @@ void WebGLRenderingContextBase::compressedTexSubImage2D(GCGLenum target, GCGLint
return;
if (!validateCompressedTexFormat("compressedTexSubImage2D", format))
return;
m_context->compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data.byteLength(), std::span(static_cast<const uint8_t*>(data.baseAddress()), data.byteLength()));
m_context->compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data.byteLength(), data.bytes());
}

bool WebGLRenderingContextBase::validateSettableTexInternalFormat(const char* functionName, GCGLenum internalFormat)
Expand Down Expand Up @@ -3899,7 +3899,7 @@ std::optional<std::span<const uint8_t>> WebGLRenderingContextBase::validateTexFu
return std::nullopt;
}
ASSERT(!offset.hasOverflowed()); // Checked already as part of `total.hasOverflowed()` check.
return std::span(static_cast<const uint8_t*>(pixels->baseAddress()) + offset.value(), dataLength);
return pixels->bytes().subspan(offset.value(), dataLength);
}

bool WebGLRenderingContextBase::validateTexFuncParameters(TexImageFunctionID functionID,
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class HTMLFastPathParser {
if (m_parsingBuffer.atEnd() || !isCharAfterTagNameOrAttribute(*m_parsingBuffer))
return didFail(HTMLFastPathResult::FailedParsingTagName, ElementName::Unknown);
skipWhile<isASCIIWhitespace>(m_parsingBuffer);
return findHTMLElementName(std::span { m_charBuffer.data(), m_charBuffer.size() });
return findHTMLElementName(m_charBuffer.span());
}
auto tagName = findHTMLElementName(std::span { start, static_cast<size_t>(m_parsingBuffer.position() - start) });
skipWhile<isASCIIWhitespace>(m_parsingBuffer);
Expand Down
8 changes: 3 additions & 5 deletions Source/WebCore/loader/DocumentWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ void DocumentWriter::replaceDocumentWithResultOfExecutingJavascriptURL(const Str
frame->protectedDocument()->setCompatibilityMode(DocumentCompatibilityMode::NoQuirksMode);
}

if (RefPtr parser = frame->document()->parser()) {
auto utf8Source = source.utf8();
parser->appendBytes(*this, reinterpret_cast<const uint8_t*>(utf8Source.data()), utf8Source.length());
}
if (RefPtr parser = frame->document()->parser())
parser->appendBytes(*this, source.utf8().bytes());
}

end();
Expand Down Expand Up @@ -317,7 +315,7 @@ void DocumentWriter::addData(const SharedBuffer& data)
return;
}
ASSERT(m_parser);
protectedParser()->appendBytes(*this, data.data(), data.size());
protectedParser()->appendBytes(*this, data.bytes());
}

void DocumentWriter::insertDataSynchronously(const String& markup)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/SinkDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SinkDocumentParser final : public RawDataDocumentParser {
}

// Ignore all data.
void appendBytes(DocumentWriter&, const uint8_t*, size_t) override
void appendBytes(DocumentWriter&, std::span<const uint8_t>) override
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/SharedBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ auto FragmentedSharedBuffer::toIPCData() const -> IPCData
{
if (useUnixDomainSockets || size() < minimumPageSize) {
return WTF::map(m_segments, [](auto& segment) {
return std::span { segment.segment->data(), segment.segment->size() };
return segment.segment->bytes();
});
}

Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/platform/SharedBufferChunkReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool SharedBufferChunkReader::nextChunk(Vector<uint8_t>& chunk, bool includeSepa
if (currentCharacter != m_separator[m_separatorIndex]) {
if (m_separatorIndex > 0) {
ASSERT_WITH_SECURITY_IMPLICATION(m_separatorIndex <= m_separator.size());
chunk.append(std::span { m_separator.data(), m_separatorIndex });
chunk.append(m_separator.span().first(m_separatorIndex));
m_separatorIndex = 0;
}
chunk.append(currentCharacter);
Expand Down Expand Up @@ -130,9 +130,8 @@ size_t SharedBufferChunkReader::peek(Vector<uint8_t>& data, size_t requestedSize
auto currentSegment = m_iteratorCurrent;

while (requestedSize && ++currentSegment != m_iteratorEnd) {
const uint8_t* segment = currentSegment->segment->data();
size_t lengthInSegment = std::min(currentSegment->segment->size(), requestedSize);
data.append(std::span { segment, lengthInSegment });
data.append(currentSegment->segment->bytes().first(lengthInSegment));
readBytesCount += lengthInSegment;
requestedSize -= lengthInSegment;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/SharedMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class SharedMemory : public ThreadSafeRefCounted<SharedMemory> {
return m_data;
}

std::span<const uint8_t> bytes() const { return { static_cast<const uint8_t*>(m_data), m_size }; }

#if OS(WINDOWS)
HANDLE handle() const { return m_handle.get(); }
#endif
Expand Down
Loading

0 comments on commit c448798

Please sign in to comment.