mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibWeb: Avoid needless copies during Blob construction
This commit is contained in:
parent
5806eeec08
commit
ac36d272d3
2 changed files with 4 additions and 5 deletions
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace Web::FileAPI {
|
namespace Web::FileAPI {
|
||||||
|
|
||||||
Blob::Blob(ByteBuffer const& byte_buffer, String const& type)
|
Blob::Blob(ByteBuffer byte_buffer, String type)
|
||||||
: m_byte_buffer(move(byte_buffer))
|
: m_byte_buffer(move(byte_buffer))
|
||||||
, m_type(move(type))
|
, m_type(move(type))
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::create(Optional<Vector<BlobPart>> co
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Return a Blob object referring to bytes as its associated byte sequence, with its size set to the length of bytes, and its type set to the value of t from the substeps above.
|
// 4. Return a Blob object referring to bytes as its associated byte sequence, with its size set to the length of bytes, and its type set to the value of t from the substeps above.
|
||||||
return adopt_ref(*new Blob(byte_buffer, type));
|
return adopt_ref(*new Blob(move(byte_buffer), move(type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::create_with_global_object(Bindings::WindowObject&, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::create_with_global_object(Bindings::WindowObject&, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||||
|
@ -149,7 +149,7 @@ DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::slice(Optional<i64> start, Optional<
|
||||||
auto byte_buffer_or_error = m_byte_buffer.slice(relative_start, span);
|
auto byte_buffer_or_error = m_byte_buffer.slice(relative_start, span);
|
||||||
if (byte_buffer_or_error.is_error())
|
if (byte_buffer_or_error.is_error())
|
||||||
return DOM::UnknownError::create("Out of memory."sv);
|
return DOM::UnknownError::create("Out of memory."sv);
|
||||||
return adopt_ref(*new Blob(byte_buffer_or_error.release_value(), relative_content_type));
|
return adopt_ref(*new Blob(byte_buffer_or_error.release_value(), move(relative_content_type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dom-blob-text
|
// https://w3c.github.io/FileAPI/#dom-blob-text
|
||||||
|
|
|
@ -33,8 +33,7 @@ class Blob
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::BlobWrapper;
|
using WrapperType = Bindings::BlobWrapper;
|
||||||
|
Blob(ByteBuffer byte_buffer, String type);
|
||||||
Blob(ByteBuffer const& byte_buffer, String const& type);
|
|
||||||
|
|
||||||
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create(Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create(Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||||
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create_with_global_object(Bindings::WindowObject&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create_with_global_object(Bindings::WindowObject&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue