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

Side by Side Diff: src/string-stream.cc

Issue 334763003: Start using OStreams. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Reformatted. Feedback addressed. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/string-stream.h ('k') | src/types.h » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project 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 "src/string-stream.h" 5 #include "src/string-stream.h"
6 6
7 #include "src/handles-inl.h" 7 #include "src/handles-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 static const int kMentionedObjectCacheMaxSize = 256; 12 static const int kMentionedObjectCacheMaxSize = 256;
13 13
14 char* HeapStringAllocator::allocate(unsigned bytes) { 14 char* HeapStringAllocator::allocate(unsigned bytes) {
15 space_ = NewArray<char>(bytes); 15 space_ = NewArray<char>(bytes);
16 return space_; 16 return space_;
17 } 17 }
18 18
19 19
20 NoAllocationStringAllocator::NoAllocationStringAllocator(char* memory,
21 unsigned size) {
22 size_ = size;
23 space_ = memory;
24 }
25
26
27 bool StringStream::Put(char c) { 20 bool StringStream::Put(char c) {
28 if (full()) return false; 21 if (full()) return false;
29 ASSERT(length_ < capacity_); 22 ASSERT(length_ < capacity_);
30 // Since the trailing '\0' is not accounted for in length_ fullness is 23 // Since the trailing '\0' is not accounted for in length_ fullness is
31 // indicated by a difference of 1 between length_ and capacity_. Thus when 24 // indicated by a difference of 1 between length_ and capacity_. Thus when
32 // reaching a difference of 2 we need to grow the buffer. 25 // reaching a difference of 2 we need to grow the buffer.
33 if (length_ == capacity_ - 2) { 26 if (length_ == capacity_ - 2) {
34 unsigned new_capacity = capacity_; 27 unsigned new_capacity = capacity_;
35 char* new_buffer = allocator_->grow(&new_capacity); 28 char* new_buffer = allocator_->grow(&new_capacity);
36 if (new_capacity > capacity_) { 29 if (new_capacity > capacity_) {
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return space_; 541 return space_;
549 } 542 }
550 MemCopy(new_space, space_, *bytes); 543 MemCopy(new_space, space_, *bytes);
551 *bytes = new_bytes; 544 *bytes = new_bytes;
552 DeleteArray(space_); 545 DeleteArray(space_);
553 space_ = new_space; 546 space_ = new_space;
554 return new_space; 547 return new_space;
555 } 548 }
556 549
557 550
558 // Only grow once to the maximum allowable size.
559 char* NoAllocationStringAllocator::grow(unsigned* bytes) {
560 ASSERT(size_ >= *bytes);
561 *bytes = size_;
562 return space_;
563 }
564
565
566 } } // namespace v8::internal 551 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/string-stream.h ('k') | src/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698