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

Side by Side Diff: mojo/public/bindings/lib/buffer.cc

Issue 76943002: Have ScratchBuffer::Allocate prefer allocating on the stack even if a previous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to other CL Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/tests/buffer_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "mojo/public/bindings/lib/buffer.h" 5 #include "mojo/public/bindings/lib/buffer.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 16 matching lines...) Expand all
27 while (overflow_) { 27 while (overflow_) {
28 Segment* doomed = overflow_; 28 Segment* doomed = overflow_;
29 overflow_ = overflow_->next; 29 overflow_ = overflow_->next;
30 free(doomed); 30 free(doomed);
31 } 31 }
32 } 32 }
33 33
34 void* ScratchBuffer::Allocate(size_t delta) { 34 void* ScratchBuffer::Allocate(size_t delta) {
35 delta = internal::Align(delta); 35 delta = internal::Align(delta);
36 36
37 void* result = 37 void* result = AllocateInSegment(&fixed_, delta);
38 AllocateInSegment((overflow_ != NULL) ? overflow_ : &fixed_, delta);
39 if (result) 38 if (result)
40 return result; 39 return result;
41 40
41 if (overflow_) {
42 result = AllocateInSegment(overflow_, delta);
43 if (result)
44 return result;
45 }
46
42 AddOverflowSegment(delta); 47 AddOverflowSegment(delta);
43 return Allocate(delta); 48 return AllocateInSegment(overflow_, delta);
44 } 49 }
45 50
46 void* ScratchBuffer::AllocateInSegment(Segment* segment, size_t delta) { 51 void* ScratchBuffer::AllocateInSegment(Segment* segment, size_t delta) {
47 void* result; 52 void* result;
48 if (static_cast<size_t>(segment->end - segment->cursor) >= delta) { 53 if (static_cast<size_t>(segment->end - segment->cursor) >= delta) {
49 result = segment->cursor; 54 result = segment->cursor;
50 memset(result, 0, delta); 55 memset(result, 0, delta);
51 segment->cursor += delta; 56 segment->cursor += delta;
52 } else { 57 } else {
53 result = NULL; 58 result = NULL;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 105
101 void* FixedBuffer::Leak() { 106 void* FixedBuffer::Leak() {
102 char* ptr = ptr_; 107 char* ptr = ptr_;
103 ptr_ = NULL; 108 ptr_ = NULL;
104 cursor_ = 0; 109 cursor_ = 0;
105 size_ = 0; 110 size_ = 0;
106 return ptr; 111 return ptr;
107 } 112 }
108 113
109 } // namespace mojo 114 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/public/tests/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698