OLD | NEW |
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 #ifndef V8_STRING_BUILDER_H_ | 5 #ifndef V8_STRING_BUILDER_H_ |
6 #define V8_STRING_BUILDER_H_ | 6 #define V8_STRING_BUILDER_H_ |
7 | 7 |
8 #include "src/assert-scope.h" | 8 #include "src/assert-scope.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/handles.h" | 10 #include "src/handles.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 }; | 339 }; |
340 | 340 |
341 template <typename DestChar> | 341 template <typename DestChar> |
342 class NoExtendString : public NoExtend<DestChar> { | 342 class NoExtendString : public NoExtend<DestChar> { |
343 public: | 343 public: |
344 NoExtendString(Handle<String> string, int required_length) | 344 NoExtendString(Handle<String> string, int required_length) |
345 : NoExtend<DestChar>(string, 0), string_(string) { | 345 : NoExtend<DestChar>(string, 0), string_(string) { |
346 DCHECK(string->length() >= required_length); | 346 DCHECK(string->length() >= required_length); |
347 } | 347 } |
348 | 348 |
349 Handle<String> Finalize() { | 349 ~NoExtendString() { |
350 Handle<SeqString> string = Handle<SeqString>::cast(string_); | 350 Handle<SeqString> string = Handle<SeqString>::cast(string_); |
351 int length = NoExtend<DestChar>::written(); | 351 int length = NoExtend<DestChar>::written(); |
352 Handle<String> result = SeqString::Truncate(string, length); | 352 *string_.location() = *SeqString::Truncate(string, length); |
353 string_ = Handle<String>(); | |
354 return result; | |
355 } | 353 } |
356 | 354 |
357 private: | 355 private: |
358 Handle<String> string_; | 356 Handle<String> string_; |
359 }; | 357 }; |
360 | 358 |
361 template <typename DestChar> | 359 template <typename DestChar> |
362 class NoExtendBuilder : public NoExtend<DestChar> { | 360 class NoExtendBuilder : public NoExtend<DestChar> { |
363 public: | 361 public: |
364 NoExtendBuilder(IncrementalStringBuilder* builder, int required_length) | 362 NoExtendBuilder(IncrementalStringBuilder* builder, int required_length) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 DCHECK_EQ(String::TWO_BYTE_ENCODING, encoding_); | 426 DCHECK_EQ(String::TWO_BYTE_ENCODING, encoding_); |
429 SeqTwoByteString::cast(*current_part_) | 427 SeqTwoByteString::cast(*current_part_) |
430 ->SeqTwoByteStringSet(current_index_++, c); | 428 ->SeqTwoByteStringSet(current_index_++, c); |
431 } | 429 } |
432 if (current_index_ == part_length_) Extend(); | 430 if (current_index_ == part_length_) Extend(); |
433 } | 431 } |
434 } // namespace internal | 432 } // namespace internal |
435 } // namespace v8 | 433 } // namespace v8 |
436 | 434 |
437 #endif // V8_STRING_BUILDER_H_ | 435 #endif // V8_STRING_BUILDER_H_ |
OLD | NEW |