Skip to content

Commit

Permalink
[DevTools] Remove the && functions from protocol::Binary.
Browse files Browse the repository at this point in the history
Just using std::move appropriately is probably
sufficient for avoiding extra copies and it's
easier to understand what's going on. Also less code.

Bug: chromium:891377
Change-Id: I321e969bdede991c223cf842a6a572704d060f11
Reviewed-on: https://chromium-review.googlesource.com/c/1302109
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603251}
  • Loading branch information
Johannes Henkel authored and Commit Bot committed Oct 26, 2018
1 parent d49f95c commit fa7b5bc
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 44 deletions.
16 changes: 2 additions & 14 deletions content/browser/devtools/protocol_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,13 @@ Binary Binary::fromRefCounted(scoped_refptr<base::RefCountedMemory> memory) {
}

// static
Binary Binary::fromVector(std::vector<uint8_t>&& data) {
Binary Binary::fromVector(std::vector<uint8_t> data) {
return Binary(base::RefCountedBytes::TakeVector(&data));
}

// static
Binary Binary::fromVector(const std::vector<uint8_t>& data) {
std::vector<uint8_t> copied_data(data);
return Binary(base::RefCountedBytes::TakeVector(&copied_data));
}

// static
Binary Binary::fromString(std::string&& data) {
Binary Binary::fromString(std::string data) {
return Binary(base::RefCountedString::TakeString(&data));
}

// static
Binary Binary::fromString(const std::string& data) {
std::string copied_data(data);
return Binary(base::RefCountedString::TakeString(&copied_data));
}
} // namespace protocol
} // namespace content
6 changes: 2 additions & 4 deletions content/browser/devtools/protocol_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ class CONTENT_EXPORT Binary {

static Binary fromBase64(const String& base64, bool* success);
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t>&& data);
static Binary fromVector(const std::vector<uint8_t>& data);
static Binary fromString(std::string&& data);
static Binary fromString(const std::string& data);
static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data);

private:
explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
Expand Down
16 changes: 2 additions & 14 deletions headless/lib/browser/protocol/protocol_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,13 @@ Binary Binary::fromRefCounted(scoped_refptr<base::RefCountedMemory> memory) {
}

// static
Binary Binary::fromVector(std::vector<uint8_t>&& data) {
Binary Binary::fromVector(std::vector<uint8_t> data) {
return Binary(base::RefCountedBytes::TakeVector(&data));
}

// static
Binary Binary::fromVector(const std::vector<uint8_t>& data) {
std::vector<uint8_t> copied_data(data);
return Binary(base::RefCountedBytes::TakeVector(&copied_data));
}

// static
Binary Binary::fromString(std::string&& data) {
Binary Binary::fromString(std::string data) {
return Binary(base::RefCountedString::TakeString(&data));
}

// static
Binary Binary::fromString(const std::string& data) {
std::string copied_data(data);
return Binary(base::RefCountedString::TakeString(&copied_data));
}
} // namespace protocol
} // namespace headless
6 changes: 2 additions & 4 deletions headless/lib/browser/protocol/protocol_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ class HEADLESS_EXPORT Binary {
String toBase64() const;
static Binary fromBase64(const String& base64, bool* success);
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t>&& data);
static Binary fromVector(const std::vector<uint8_t>& data);
static Binary fromString(std::string&& data);
static Binary fromString(const std::string& data);
static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data);

private:
explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,10 @@ Binary Binary::fromSharedBuffer(scoped_refptr<SharedBuffer> buffer) {
}

// static
Binary Binary::fromVector(Vector<uint8_t>&& in) {
Binary Binary::fromVector(Vector<uint8_t> in) {
return Binary(base::AdoptRef(new BinaryBasedOnVector(std::move(in))));
}

// static
Binary Binary::fromVector(const Vector<uint8_t>& in) {
return Binary(base::AdoptRef(new BinaryBasedOnVector(in)));
}

// static
Binary Binary::fromCachedData(
std::unique_ptr<v8::ScriptCompiler::CachedData> data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ class CORE_EXPORT Binary {
String toBase64() const;
static Binary fromBase64(const String& base64, bool* success);
static Binary fromSharedBuffer(scoped_refptr<SharedBuffer> buffer);
static Binary fromVector(Vector<uint8_t>&& in);
static Binary fromVector(const Vector<uint8_t>& in);
static Binary fromVector(Vector<uint8_t> in);

// Note: |data.buffer_policy| must be
// ScriptCompiler::ScriptCompiler::CachedData::BufferOwned.
Expand Down

0 comments on commit fa7b5bc

Please sign in to comment.