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

Side by Side Diff: components/network_hints/renderer/dns_prefetch_queue.h

Issue 1349783006: Cleanup: Pass std::string as const reference if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert third_party changes Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // DnsQueue is implemented as an almost FIFO circular buffer for text 5 // DnsQueue is implemented as an almost FIFO circular buffer for text
6 // strings that don't have embedded nulls ('\0'). The "almost" element is that 6 // strings that don't have embedded nulls ('\0'). The "almost" element is that
7 // some duplicate strings may be removed (i.e., the string won't really be 7 // some duplicate strings may be removed (i.e., the string won't really be
8 // pushed *if* the class happens to notice that a duplicate is already in the 8 // pushed *if* the class happens to notice that a duplicate is already in the
9 // queue). 9 // queue).
10 // The buffers internal format is null terminated character strings 10 // The buffers internal format is null terminated character strings
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // Push takes an unterminated string of the given length 56 // Push takes an unterminated string of the given length
57 // and inserts it into the queue for later 57 // and inserts it into the queue for later
58 // extraction by read. For each successful push(), there 58 // extraction by read. For each successful push(), there
59 // can later be a corresponding read() to extracted the text. 59 // can later be a corresponding read() to extracted the text.
60 // The string must not contain an embedded null terminator 60 // The string must not contain an embedded null terminator
61 // Exactly length chars are written, or the push fails (where 61 // Exactly length chars are written, or the push fails (where
62 // "fails" means nothing is written). 62 // "fails" means nothing is written).
63 // Returns true for success, false for failure (nothing written). 63 // Returns true for success, false for failure (nothing written).
64 PushResult Push(const char* source, const size_t length); 64 PushResult Push(const char* source, const size_t length);
65 65
66 PushResult Push(std::string source) { 66 PushResult Push(const std::string& source) {
67 return Push(source.c_str(), source.length()); 67 return Push(source.c_str(), source.length());
68 } 68 }
69 69
70 // Extract the next available string from the buffer. 70 // Extract the next available string from the buffer.
71 // If the buffer is empty, then return false. 71 // If the buffer is empty, then return false.
72 bool Pop(std::string* out_string); 72 bool Pop(std::string* out_string);
73 73
74 private: 74 private:
75 bool Validate(); // Checks that all internal data is valid. 75 bool Validate(); // Checks that all internal data is valid.
76 76
77 const scoped_ptr<char[]> buffer_; // Circular buffer, plus extra char ('\0'). 77 const scoped_ptr<char[]> buffer_; // Circular buffer, plus extra char ('\0').
78 const BufferSize buffer_size_; // Size one smaller than allocated space. 78 const BufferSize buffer_size_; // Size one smaller than allocated space.
79 const BufferSize buffer_sentinel_; // Index of extra '\0' at end of buffer_. 79 const BufferSize buffer_sentinel_; // Index of extra '\0' at end of buffer_.
80 80
81 // If writable_ == readable_, then the buffer is empty. 81 // If writable_ == readable_, then the buffer is empty.
82 BufferSize readable_; // Next readable char in buffer_. 82 BufferSize readable_; // Next readable char in buffer_.
83 BufferSize writeable_; // The next space in buffer_ to push. 83 BufferSize writeable_; // The next space in buffer_ to push.
84 84
85 // Number of queued strings 85 // Number of queued strings
86 size_t size_; 86 size_t size_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(DnsQueue); 88 DISALLOW_COPY_AND_ASSIGN(DnsQueue);
89 }; // class DnsQueue 89 }; // class DnsQueue
90 90
91 } // namespace network_hints 91 } // namespace network_hints
92 92
93 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ 93 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698