Commit 7802e965 authored by Victor Vasiliev's avatar Victor Vasiliev Committed by Commit Bot

Platformize UnsafeArena in SPDY code

Merge internal change: 228810977

R=rch@chromium.org

Change-Id: Iaa05eb7fe97ea0c3d326c8530d52be8a2a7573cd
Reviewed-on: https://chromium-review.googlesource.com/c/1406162Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Commit-Queue: Victor Vasiliev <vasilvv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622140}
parent 6d1486b6
...@@ -429,8 +429,6 @@ component("net") { ...@@ -429,8 +429,6 @@ component("net") {
"android/traffic_stats.h", "android/traffic_stats.h",
"base/address_tracker_linux.cc", "base/address_tracker_linux.cc",
"base/address_tracker_linux.h", "base/address_tracker_linux.h",
"base/arena.cc",
"base/arena.h",
"base/backoff_entry.cc", "base/backoff_entry.cc",
"base/backoff_entry.h", "base/backoff_entry.h",
"base/backoff_entry_serializer.cc", "base/backoff_entry_serializer.cc",
...@@ -1694,6 +1692,7 @@ component("net") { ...@@ -1694,6 +1692,7 @@ component("net") {
"third_party/spdy/platform/api/spdy_string.h", "third_party/spdy/platform/api/spdy_string.h",
"third_party/spdy/platform/api/spdy_string_piece.h", "third_party/spdy/platform/api/spdy_string_piece.h",
"third_party/spdy/platform/api/spdy_string_utils.h", "third_party/spdy/platform/api/spdy_string_utils.h",
"third_party/spdy/platform/api/spdy_unsafe_arena.h",
"third_party/spdy/platform/impl/spdy_arraysize_impl.h", "third_party/spdy/platform/impl/spdy_arraysize_impl.h",
"third_party/spdy/platform/impl/spdy_containers_impl.h", "third_party/spdy/platform/impl/spdy_containers_impl.h",
"third_party/spdy/platform/impl/spdy_endianness_util_impl.h", "third_party/spdy/platform/impl/spdy_endianness_util_impl.h",
...@@ -1708,6 +1707,8 @@ component("net") { ...@@ -1708,6 +1707,8 @@ component("net") {
"third_party/spdy/platform/impl/spdy_string_piece_impl.h", "third_party/spdy/platform/impl/spdy_string_piece_impl.h",
"third_party/spdy/platform/impl/spdy_string_utils_impl.cc", "third_party/spdy/platform/impl/spdy_string_utils_impl.cc",
"third_party/spdy/platform/impl/spdy_string_utils_impl.h", "third_party/spdy/platform/impl/spdy_string_utils_impl.h",
"third_party/spdy/platform/impl/spdy_unsafe_arena_impl.cc",
"third_party/spdy/platform/impl/spdy_unsafe_arena_impl.h",
"url_request/data_protocol_handler.cc", "url_request/data_protocol_handler.cc",
"url_request/data_protocol_handler.h", "url_request/data_protocol_handler.h",
"url_request/http_user_agent_settings.h", "url_request/http_user_agent_settings.h",
...@@ -4733,7 +4734,6 @@ test("net_unittests") { ...@@ -4733,7 +4734,6 @@ test("net_unittests") {
"base/address_family_unittest.cc", "base/address_family_unittest.cc",
"base/address_list_unittest.cc", "base/address_list_unittest.cc",
"base/address_tracker_linux_unittest.cc", "base/address_tracker_linux_unittest.cc",
"base/arena_unittest.cc",
"base/backoff_entry_serializer_unittest.cc", "base/backoff_entry_serializer_unittest.cc",
"base/backoff_entry_unittest.cc", "base/backoff_entry_unittest.cc",
"base/chunked_upload_data_stream_unittest.cc", "base/chunked_upload_data_stream_unittest.cc",
...@@ -5317,6 +5317,7 @@ test("net_unittests") { ...@@ -5317,6 +5317,7 @@ test("net_unittests") {
"third_party/spdy/core/spdy_test_utils.h", "third_party/spdy/core/spdy_test_utils.h",
"third_party/spdy/platform/api/spdy_mem_slice_test.cc", "third_party/spdy/platform/api/spdy_mem_slice_test.cc",
"third_party/spdy/platform/api/spdy_string_utils_test.cc", "third_party/spdy/platform/api/spdy_string_utils_test.cc",
"third_party/spdy/platform/impl/spdy_unsafe_arena_impl_test.cc",
"third_party/uri_template/uri_template_test.cc", "third_party/uri_template/uri_template_test.cc",
"tools/content_decoder_tool/content_decoder_tool.cc", "tools/content_decoder_tool/content_decoder_tool.cc",
"tools/content_decoder_tool/content_decoder_tool.h", "tools/content_decoder_tool/content_decoder_tool.h",
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <map> #include <map>
#include "base/rand_util.h" #include "base/rand_util.h"
#include "net/base/arena.h"
#include "net/third_party/spdy/core/hpack/hpack_huffman_table.h" #include "net/third_party/spdy/core/hpack/hpack_huffman_table.h"
#include "net/third_party/spdy/platform/api/spdy_unsafe_arena.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -200,7 +200,7 @@ class HpackEncoderTest : public ::testing::TestWithParam<bool> { ...@@ -200,7 +200,7 @@ class HpackEncoderTest : public ::testing::TestWithParam<bool> {
const HpackEntry* cookie_a_; const HpackEntry* cookie_a_;
const HpackEntry* cookie_c_; const HpackEntry* cookie_c_;
net::UnsafeArena headers_storage_; SpdyUnsafeArena headers_storage_;
std::vector<std::pair<SpdyStringPiece, SpdyStringPiece>> headers_observed_; std::vector<std::pair<SpdyStringPiece, SpdyStringPiece>> headers_observed_;
HpackOutputStream expected_; HpackOutputStream expected_;
......
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "net/base/arena.h"
#include "net/third_party/spdy/platform/api/spdy_estimate_memory_usage.h" #include "net/third_party/spdy/platform/api/spdy_estimate_memory_usage.h"
#include "net/third_party/spdy/platform/api/spdy_ptr_util.h" #include "net/third_party/spdy/platform/api/spdy_ptr_util.h"
#include "net/third_party/spdy/platform/api/spdy_string_utils.h" #include "net/third_party/spdy/platform/api/spdy_string_utils.h"
#include "net/third_party/spdy/platform/api/spdy_unsafe_arena.h"
namespace spdy { namespace spdy {
namespace { namespace {
...@@ -45,7 +45,7 @@ SpdyStringPiece SeparatorForKey(SpdyStringPiece key) { ...@@ -45,7 +45,7 @@ SpdyStringPiece SeparatorForKey(SpdyStringPiece key) {
} // namespace } // namespace
// This class provides a backing store for SpdyStringPieces. It previously used // This class provides a backing store for SpdyStringPieces. It previously used
// custom allocation logic, but now uses an net::UnsafeArena instead. It has the // custom allocation logic, but now uses an UnsafeArena instead. It has the
// property that SpdyStringPieces that refer to data in Storage are never // property that SpdyStringPieces that refer to data in Storage are never
// invalidated until the Storage is deleted or Clear() is called. // invalidated until the Storage is deleted or Clear() is called.
// //
...@@ -97,7 +97,7 @@ class SpdyHeaderBlock::Storage { ...@@ -97,7 +97,7 @@ class SpdyHeaderBlock::Storage {
} }
private: private:
net::UnsafeArena arena_; SpdyUnsafeArena arena_;
}; };
SpdyHeaderBlock::HeaderValue::HeaderValue(Storage* storage, SpdyHeaderBlock::HeaderValue::HeaderValue(Storage* storage,
......
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_UNSAFE_ARENA_H_
#define NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_UNSAFE_ARENA_H_
#include "net/third_party/spdy/platform/impl/spdy_unsafe_arena_impl.h"
namespace spdy {
using SpdyUnsafeArena = SpdyUnsafeArenaImpl;
} // namespace spdy
#endif // NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_UNSAFE_ARENA_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "net/base/arena.h" #include "net/third_party/spdy/platform/impl/spdy_unsafe_arena_impl.h"
#include <string.h> #include <string.h>
...@@ -10,16 +10,18 @@ ...@@ -10,16 +10,18 @@
#include "base/logging.h" #include "base/logging.h"
namespace net { namespace spdy {
UnsafeArena::UnsafeArena(size_t block_size) : block_size_(block_size) {} SpdyUnsafeArenaImpl::SpdyUnsafeArenaImpl(size_t block_size)
: block_size_(block_size) {}
UnsafeArena::~UnsafeArena() = default; SpdyUnsafeArenaImpl::~SpdyUnsafeArenaImpl() = default;
UnsafeArena::UnsafeArena(UnsafeArena&& other) = default; SpdyUnsafeArenaImpl::SpdyUnsafeArenaImpl(SpdyUnsafeArenaImpl&& other) = default;
UnsafeArena& UnsafeArena::operator=(UnsafeArena&& other) = default; SpdyUnsafeArenaImpl& SpdyUnsafeArenaImpl::operator=(
SpdyUnsafeArenaImpl&& other) = default;
char* UnsafeArena::Alloc(size_t size) { char* SpdyUnsafeArenaImpl::Alloc(size_t size) {
Reserve(size); Reserve(size);
Block& b = blocks_.back(); Block& b = blocks_.back();
DCHECK_GE(b.size, b.used + size); DCHECK_GE(b.size, b.used + size);
...@@ -28,7 +30,9 @@ char* UnsafeArena::Alloc(size_t size) { ...@@ -28,7 +30,9 @@ char* UnsafeArena::Alloc(size_t size) {
return out; return out;
} }
char* UnsafeArena::Realloc(char* original, size_t oldsize, size_t newsize) { char* SpdyUnsafeArenaImpl::Realloc(char* original,
size_t oldsize,
size_t newsize) {
DCHECK(!blocks_.empty()); DCHECK(!blocks_.empty());
Block& last = blocks_.back(); Block& last = blocks_.back();
if (last.data.get() <= original && original < last.data.get() + last.size) { if (last.data.get() <= original && original < last.data.get() + last.size) {
...@@ -48,13 +52,13 @@ char* UnsafeArena::Realloc(char* original, size_t oldsize, size_t newsize) { ...@@ -48,13 +52,13 @@ char* UnsafeArena::Realloc(char* original, size_t oldsize, size_t newsize) {
return out; return out;
} }
char* UnsafeArena::Memdup(const char* data, size_t size) { char* SpdyUnsafeArenaImpl::Memdup(const char* data, size_t size) {
char* out = Alloc(size); char* out = Alloc(size);
memcpy(out, data, size); memcpy(out, data, size);
return out; return out;
} }
void UnsafeArena::Free(char* data, size_t size) { void SpdyUnsafeArenaImpl::Free(char* data, size_t size) {
if (blocks_.empty()) { if (blocks_.empty()) {
return; return;
} }
...@@ -66,12 +70,12 @@ void UnsafeArena::Free(char* data, size_t size) { ...@@ -66,12 +70,12 @@ void UnsafeArena::Free(char* data, size_t size) {
} }
} }
void UnsafeArena::Reset() { void SpdyUnsafeArenaImpl::Reset() {
blocks_.clear(); blocks_.clear();
status_.bytes_allocated_ = 0; status_.bytes_allocated_ = 0;
} }
void UnsafeArena::Reserve(size_t additional_space) { void SpdyUnsafeArenaImpl::Reserve(size_t additional_space) {
if (blocks_.empty()) { if (blocks_.empty()) {
AllocBlock(std::max(additional_space, block_size_)); AllocBlock(std::max(additional_space, block_size_));
} else { } else {
...@@ -82,25 +86,27 @@ void UnsafeArena::Reserve(size_t additional_space) { ...@@ -82,25 +86,27 @@ void UnsafeArena::Reserve(size_t additional_space) {
} }
} }
void UnsafeArena::AllocBlock(size_t size) { void SpdyUnsafeArenaImpl::AllocBlock(size_t size) {
blocks_.push_back(Block(size)); blocks_.push_back(Block(size));
status_.bytes_allocated_ += size; status_.bytes_allocated_ += size;
} }
UnsafeArena::Block::Block(size_t s) : data(new char[s]), size(s), used(0) {} SpdyUnsafeArenaImpl::Block::Block(size_t s)
: data(new char[s]), size(s), used(0) {}
UnsafeArena::Block::~Block() = default; SpdyUnsafeArenaImpl::Block::~Block() = default;
UnsafeArena::Block::Block(UnsafeArena::Block&& other) SpdyUnsafeArenaImpl::Block::Block(SpdyUnsafeArenaImpl::Block&& other)
: size(other.size), used(other.used) { : size(other.size), used(other.used) {
data = std::move(other.data); data = std::move(other.data);
} }
UnsafeArena::Block& UnsafeArena::Block::operator=(UnsafeArena::Block&& other) { SpdyUnsafeArenaImpl::Block& SpdyUnsafeArenaImpl::Block::operator=(
SpdyUnsafeArenaImpl::Block&& other) {
size = other.size; size = other.size;
used = other.used; used = other.used;
data = std::move(other.data); data = std::move(other.data);
return *this; return *this;
} }
} // namespace net } // namespace spdy
...@@ -2,23 +2,23 @@ ...@@ -2,23 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef NET_BASE_ARENA_H_ #ifndef NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_UNSAFE_ARENA_IMPL_H_
#define NET_BASE_ARENA_H_ #define NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_UNSAFE_ARENA_IMPL_H_
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "net/base/net_export.h" #include "net/third_party/spdy/platform/api/spdy_export.h"
namespace net { namespace spdy {
// Allocates large blocks of memory, and doles them out in smaller chunks. // Allocates large blocks of memory, and doles them out in smaller chunks.
// Not thread-safe. // Not thread-safe.
class NET_EXPORT_PRIVATE UnsafeArena { class SPDY_EXPORT_PRIVATE SpdyUnsafeArenaImpl {
public: public:
class Status { class Status {
private: private:
friend class UnsafeArena; friend class SpdyUnsafeArenaImpl;
size_t bytes_allocated_; size_t bytes_allocated_;
public: public:
...@@ -27,17 +27,17 @@ class NET_EXPORT_PRIVATE UnsafeArena { ...@@ -27,17 +27,17 @@ class NET_EXPORT_PRIVATE UnsafeArena {
}; };
// Blocks allocated by this arena will be at least |block_size| bytes. // Blocks allocated by this arena will be at least |block_size| bytes.
explicit UnsafeArena(size_t block_size); explicit SpdyUnsafeArenaImpl(size_t block_size);
~UnsafeArena(); ~SpdyUnsafeArenaImpl();
// Copy and assign are not allowed. // Copy and assign are not allowed.
UnsafeArena() = delete; SpdyUnsafeArenaImpl() = delete;
UnsafeArena(const UnsafeArena&) = delete; SpdyUnsafeArenaImpl(const SpdyUnsafeArenaImpl&) = delete;
UnsafeArena& operator=(const UnsafeArena&) = delete; SpdyUnsafeArenaImpl& operator=(const SpdyUnsafeArenaImpl&) = delete;
// Move is allowed. // Move is allowed.
UnsafeArena(UnsafeArena&& other); SpdyUnsafeArenaImpl(SpdyUnsafeArenaImpl&& other);
UnsafeArena& operator=(UnsafeArena&& other); SpdyUnsafeArenaImpl& operator=(SpdyUnsafeArenaImpl&& other);
char* Alloc(size_t size); char* Alloc(size_t size);
char* Realloc(char* original, size_t oldsize, size_t newsize); char* Realloc(char* original, size_t oldsize, size_t newsize);
...@@ -72,6 +72,6 @@ class NET_EXPORT_PRIVATE UnsafeArena { ...@@ -72,6 +72,6 @@ class NET_EXPORT_PRIVATE UnsafeArena {
Status status_; Status status_;
}; };
} // namespace net } // namespace spdy
#endif // NET_BASE_ARENA_H_ #endif // NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_UNSAFE_ARENA_IMPL_H_
...@@ -2,48 +2,46 @@ ...@@ -2,48 +2,46 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "net/base/arena.h" #include "net/third_party/spdy/platform/impl/spdy_unsafe_arena_impl.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/strings/string_piece.h" #include "net/third_party/spdy/platform/api/spdy_string_piece.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::StringPiece; namespace spdy {
namespace net {
namespace { namespace {
size_t kDefaultBlockSize = 2048; size_t kDefaultBlockSize = 2048;
const char kTestString[] = "This is a decently long test string."; const char kTestString[] = "This is a decently long test string.";
TEST(UnsafeArenaTest, Memdup) { TEST(SpdyUnsafeArenaImplTest, Memdup) {
UnsafeArena arena(kDefaultBlockSize); SpdyUnsafeArenaImpl arena(kDefaultBlockSize);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
char* c = arena.Memdup(kTestString, length); char* c = arena.Memdup(kTestString, length);
EXPECT_NE(nullptr, c); EXPECT_NE(nullptr, c);
EXPECT_NE(c, kTestString); EXPECT_NE(c, kTestString);
EXPECT_EQ(StringPiece(c, length), kTestString); EXPECT_EQ(SpdyStringPiece(c, length), kTestString);
} }
TEST(UnsafeArenaTest, MemdupLargeString) { TEST(SpdyUnsafeArenaImplTest, MemdupLargeString) {
UnsafeArena arena(10 /* block size */); SpdyUnsafeArenaImpl arena(10 /* block size */);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
char* c = arena.Memdup(kTestString, length); char* c = arena.Memdup(kTestString, length);
EXPECT_NE(nullptr, c); EXPECT_NE(nullptr, c);
EXPECT_NE(c, kTestString); EXPECT_NE(c, kTestString);
EXPECT_EQ(StringPiece(c, length), kTestString); EXPECT_EQ(SpdyStringPiece(c, length), kTestString);
} }
TEST(UnsafeArenaTest, MultipleBlocks) { TEST(SpdyUnsafeArenaImplTest, MultipleBlocks) {
UnsafeArena arena(40 /* block size */); SpdyUnsafeArenaImpl arena(40 /* block size */);
std::vector<std::string> strings = { std::vector<std::string> strings = {
"One decently long string.", "Another string.", "One decently long string.", "Another string.",
"A third string that will surely go in a different block."}; "A third string that will surely go in a different block."};
std::vector<StringPiece> copies; std::vector<SpdyStringPiece> copies;
for (const std::string& s : strings) { for (const std::string& s : strings) {
StringPiece sp(arena.Memdup(s.data(), s.size()), s.size()); SpdyStringPiece sp(arena.Memdup(s.data(), s.size()), s.size());
copies.push_back(sp); copies.push_back(sp);
} }
EXPECT_EQ(strings.size(), copies.size()); EXPECT_EQ(strings.size(), copies.size());
...@@ -52,19 +50,19 @@ TEST(UnsafeArenaTest, MultipleBlocks) { ...@@ -52,19 +50,19 @@ TEST(UnsafeArenaTest, MultipleBlocks) {
} }
} }
TEST(UnsafeArenaTest, UseAfterReset) { TEST(SpdyUnsafeArenaImplTest, UseAfterReset) {
UnsafeArena arena(kDefaultBlockSize); SpdyUnsafeArenaImpl arena(kDefaultBlockSize);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
char* c = arena.Memdup(kTestString, length); char* c = arena.Memdup(kTestString, length);
arena.Reset(); arena.Reset();
c = arena.Memdup(kTestString, length); c = arena.Memdup(kTestString, length);
EXPECT_NE(nullptr, c); EXPECT_NE(nullptr, c);
EXPECT_NE(c, kTestString); EXPECT_NE(c, kTestString);
EXPECT_EQ(StringPiece(c, length), kTestString); EXPECT_EQ(SpdyStringPiece(c, length), kTestString);
} }
TEST(UnsafeArenaTest, Free) { TEST(SpdyUnsafeArenaImplTest, Free) {
UnsafeArena arena(kDefaultBlockSize); SpdyUnsafeArenaImpl arena(kDefaultBlockSize);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
// Freeing memory not owned by the arena should be a no-op, and freeing // Freeing memory not owned by the arena should be a no-op, and freeing
// before any allocations from the arena should be a no-op. // before any allocations from the arena should be a no-op.
...@@ -89,8 +87,8 @@ TEST(UnsafeArenaTest, Free) { ...@@ -89,8 +87,8 @@ TEST(UnsafeArenaTest, Free) {
EXPECT_EQ(c4, c5); EXPECT_EQ(c4, c5);
} }
TEST(UnsafeArenaTest, Alloc) { TEST(SpdyUnsafeArenaImplTest, Alloc) {
UnsafeArena arena(kDefaultBlockSize); SpdyUnsafeArenaImpl arena(kDefaultBlockSize);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
char* c1 = arena.Alloc(length); char* c1 = arena.Alloc(length);
char* c2 = arena.Alloc(2 * length); char* c2 = arena.Alloc(2 * length);
...@@ -99,40 +97,40 @@ TEST(UnsafeArenaTest, Alloc) { ...@@ -99,40 +97,40 @@ TEST(UnsafeArenaTest, Alloc) {
EXPECT_EQ(c1 + length, c2); EXPECT_EQ(c1 + length, c2);
EXPECT_EQ(c2 + 2 * length, c3); EXPECT_EQ(c2 + 2 * length, c3);
EXPECT_EQ(c3 + 3 * length, c4); EXPECT_EQ(c3 + 3 * length, c4);
EXPECT_EQ(StringPiece(c4, length), kTestString); EXPECT_EQ(SpdyStringPiece(c4, length), kTestString);
} }
TEST(UnsafeArenaTest, Realloc) { TEST(SpdyUnsafeArenaImplTest, Realloc) {
UnsafeArena arena(kDefaultBlockSize); SpdyUnsafeArenaImpl arena(kDefaultBlockSize);
const size_t length = strlen(kTestString); const size_t length = strlen(kTestString);
// Simple realloc that fits in the block. // Simple realloc that fits in the block.
char* c1 = arena.Memdup(kTestString, length); char* c1 = arena.Memdup(kTestString, length);
char* c2 = arena.Realloc(c1, length, 2 * length); char* c2 = arena.Realloc(c1, length, 2 * length);
EXPECT_TRUE(c1); EXPECT_TRUE(c1);
EXPECT_EQ(c1, c2); EXPECT_EQ(c1, c2);
EXPECT_EQ(StringPiece(c1, length), kTestString); EXPECT_EQ(SpdyStringPiece(c1, length), kTestString);
// Multiple reallocs. // Multiple reallocs.
char* c3 = arena.Memdup(kTestString, length); char* c3 = arena.Memdup(kTestString, length);
EXPECT_EQ(c2 + 2 * length, c3); EXPECT_EQ(c2 + 2 * length, c3);
EXPECT_EQ(StringPiece(c3, length), kTestString); EXPECT_EQ(SpdyStringPiece(c3, length), kTestString);
char* c4 = arena.Realloc(c3, length, 2 * length); char* c4 = arena.Realloc(c3, length, 2 * length);
EXPECT_EQ(c3, c4); EXPECT_EQ(c3, c4);
EXPECT_EQ(StringPiece(c4, length), kTestString); EXPECT_EQ(SpdyStringPiece(c4, length), kTestString);
char* c5 = arena.Realloc(c4, 2 * length, 3 * length); char* c5 = arena.Realloc(c4, 2 * length, 3 * length);
EXPECT_EQ(c4, c5); EXPECT_EQ(c4, c5);
EXPECT_EQ(StringPiece(c5, length), kTestString); EXPECT_EQ(SpdyStringPiece(c5, length), kTestString);
char* c6 = arena.Memdup(kTestString, length); char* c6 = arena.Memdup(kTestString, length);
EXPECT_EQ(c5 + 3 * length, c6); EXPECT_EQ(c5 + 3 * length, c6);
EXPECT_EQ(StringPiece(c6, length), kTestString); EXPECT_EQ(SpdyStringPiece(c6, length), kTestString);
// Realloc that does not fit in the remainder of the first block. // Realloc that does not fit in the remainder of the first block.
char* c7 = arena.Realloc(c6, length, kDefaultBlockSize); char* c7 = arena.Realloc(c6, length, kDefaultBlockSize);
EXPECT_EQ(StringPiece(c7, length), kTestString); EXPECT_EQ(SpdyStringPiece(c7, length), kTestString);
arena.Free(c7, kDefaultBlockSize); arena.Free(c7, kDefaultBlockSize);
char* c8 = arena.Memdup(kTestString, length); char* c8 = arena.Memdup(kTestString, length);
EXPECT_NE(c6, c7); EXPECT_NE(c6, c7);
EXPECT_EQ(c7, c8); EXPECT_EQ(c7, c8);
EXPECT_EQ(StringPiece(c8, length), kTestString); EXPECT_EQ(SpdyStringPiece(c8, length), kTestString);
} }
} // namespace } // namespace
} // namespace net } // namespace spdy
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment