Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1165)

Side by Side Diff: net/base/arena.h

Issue 2611173004: Modify SpdyHeaderBlock's internals to consolidate header values only on first access. (Closed)
Patch Set: Rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/arena.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_ARENA_H_ 5 #ifndef NET_BASE_ARENA_H_
6 #define NET_BASE_ARENA_H_ 6 #define NET_BASE_ARENA_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "net/base/net_export.h" 11 #include "net/base/net_export.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 // Allocates large blocks of memory, and doles them out in smaller chunks. 15 // Allocates large blocks of memory, and doles them out in smaller chunks.
16 // Not thread-safe. 16 // Not thread-safe.
17 class NET_EXPORT_PRIVATE UnsafeArena { 17 class NET_EXPORT_PRIVATE UnsafeArena {
18 public: 18 public:
19 class Status {
20 private:
21 friend class UnsafeArena;
22 size_t bytes_allocated_;
23
24 public:
25 Status() : bytes_allocated_(0) {}
26 size_t bytes_allocated() const { return bytes_allocated_; }
27 };
28
19 // Blocks allocated by this arena will be at least |block_size| bytes. 29 // Blocks allocated by this arena will be at least |block_size| bytes.
20 explicit UnsafeArena(size_t block_size); 30 explicit UnsafeArena(size_t block_size);
21 ~UnsafeArena(); 31 ~UnsafeArena();
22 32
23 // Copy and assign are not allowed. 33 // Copy and assign are not allowed.
24 UnsafeArena() = delete; 34 UnsafeArena() = delete;
25 UnsafeArena(const UnsafeArena&) = delete; 35 UnsafeArena(const UnsafeArena&) = delete;
26 UnsafeArena& operator=(const UnsafeArena&) = delete; 36 UnsafeArena& operator=(const UnsafeArena&) = delete;
27 37
28 // Move is allowed. 38 // Move is allowed.
29 UnsafeArena(UnsafeArena&& other); 39 UnsafeArena(UnsafeArena&& other);
30 UnsafeArena& operator=(UnsafeArena&& other); 40 UnsafeArena& operator=(UnsafeArena&& other);
31 41
32 char* Alloc(size_t size); 42 char* Alloc(size_t size);
33 char* Realloc(char* original, size_t oldsize, size_t newsize); 43 char* Realloc(char* original, size_t oldsize, size_t newsize);
34 char* Memdup(const char* data, size_t size); 44 char* Memdup(const char* data, size_t size);
35 45
36 // If |data| and |size| describe the most recent allocation made from this 46 // If |data| and |size| describe the most recent allocation made from this
37 // arena, the memory is reclaimed. Otherwise, this method is a no-op. 47 // arena, the memory is reclaimed. Otherwise, this method is a no-op.
38 void Free(char* data, size_t size); 48 void Free(char* data, size_t size);
39 49
40 void Reset(); 50 void Reset();
41 51
52 Status status() const { return status_; }
53
42 private: 54 private:
43 struct Block { 55 struct Block {
44 std::unique_ptr<char[]> data; 56 std::unique_ptr<char[]> data;
45 size_t size = 0; 57 size_t size = 0;
46 size_t used = 0; 58 size_t used = 0;
47 59
48 explicit Block(size_t s); 60 explicit Block(size_t s);
49 ~Block(); 61 ~Block();
50 62
51 Block(Block&& other); 63 Block(Block&& other);
52 Block& operator=(Block&& other); 64 Block& operator=(Block&& other);
53 }; 65 };
54 66
55 void Reserve(size_t additional_space); 67 void Reserve(size_t additional_space);
56 void AllocBlock(size_t size); 68 void AllocBlock(size_t size);
57 69
58 size_t block_size_; 70 size_t block_size_;
59 std::vector<Block> blocks_; 71 std::vector<Block> blocks_;
72 Status status_;
60 }; 73 };
61 74
62 } // namespace net 75 } // namespace net
63 76
64 #endif // NET_BASE_ARENA_H_ 77 #endif // NET_BASE_ARENA_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/arena.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698