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

Side by Side Diff: courgette/memory_allocator.h

Issue 565753002: Make Courgette as much as 5x faster. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | 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) 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 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_ 5 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_
6 #define COURGETTE_MEMORY_ALLOCATOR_H_ 6 #define COURGETTE_MEMORY_ALLOCATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 CheckBool reserve(size_t size) WARN_UNUSED_RESULT { 326 CheckBool reserve(size_t size) WARN_UNUSED_RESULT {
327 if (failed()) 327 if (failed())
328 return false; 328 return false;
329 329
330 if (size <= alloc_size_) 330 if (size <= alloc_size_)
331 return true; 331 return true;
332 332
333 if (size < kStartSize) 333 if (size < kStartSize)
334 size = kStartSize; 334 size = kStartSize;
335 335
336 // Use a size 1% higher than requested. In practice, this makes Courgette as
337 // much as 5x faster on typical Chrome update payloads as a lot of future
338 // reserve() calls will become no-ops instead of costly resizes that copy
339 // all the data. Note that doing this here instead of outside the function
340 // is more efficient, since it's after the no-op early return checks above.
341 size *= 1.01;
gab 2014/09/12 04:12:19 This will have no impact on reserves below 100, sh
gab 2014/09/12 04:16:06 Oops s/multiple of 2/power of 2/ of course.
336 T* new_buffer = alloc_.allocate(size); 342 T* new_buffer = alloc_.allocate(size);
337 if (!new_buffer) { 343 if (!new_buffer) {
338 clear(); 344 clear();
339 alloc_size_ = kAllocationFailure; 345 alloc_size_ = kAllocationFailure;
340 } else { 346 } else {
341 if (buffer_) { 347 if (buffer_) {
342 memcpy(new_buffer, buffer_, size_ * sizeof(T)); 348 memcpy(new_buffer, buffer_, size_ * sizeof(T));
343 alloc_.deallocate(buffer_, alloc_size_); 349 alloc_.deallocate(buffer_, alloc_size_);
344 } 350 }
345 buffer_ = new_buffer; 351 buffer_ = new_buffer;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 protected: 463 protected:
458 T* buffer_; 464 T* buffer_;
459 size_t size_; // how much of the buffer we're using. 465 size_t size_; // how much of the buffer we're using.
460 size_t alloc_size_; // how much space we have allocated. 466 size_t alloc_size_; // how much space we have allocated.
461 Allocator alloc_; 467 Allocator alloc_;
462 }; 468 };
463 469
464 } // namespace courgette 470 } // namespace courgette
465 471
466 #endif // COURGETTE_MEMORY_ALLOCATOR_H_ 472 #endif // COURGETTE_MEMORY_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698