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

Side by Side Diff: src/parsing/scanner.h

Issue 1919673006: Prevent unnecessary memory (de-)allocations in LiteralBuffer::CopyFrom. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 // Features shared by parsing and pre-parsing scanners. 5 // Features shared by parsing and pre-parsing scanners.
6 6
7 #ifndef V8_PARSING_SCANNER_H_ 7 #ifndef V8_PARSING_SCANNER_H_
8 #define V8_PARSING_SCANNER_H_ 8 #define V8_PARSING_SCANNER_H_
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 219
220 Handle<String> Internalize(Isolate* isolate) const; 220 Handle<String> Internalize(Isolate* isolate) const;
221 221
222 void CopyFrom(const LiteralBuffer* other) { 222 void CopyFrom(const LiteralBuffer* other) {
223 if (other == nullptr) { 223 if (other == nullptr) {
224 Reset(); 224 Reset();
225 } else { 225 } else {
226 is_one_byte_ = other->is_one_byte_; 226 is_one_byte_ = other->is_one_byte_;
227 position_ = other->position_; 227 position_ = other->position_;
228 backing_store_.Dispose(); 228 if (position_ < backing_store_.length()) {
229 backing_store_ = other->backing_store_.Clone(); 229 std::copy(other->backing_store_.begin(),
230 other->backing_store_.begin() + position_,
231 backing_store_.begin());
232 } else {
233 backing_store_.Dispose();
234 backing_store_ = other->backing_store_.Clone();
235 }
230 } 236 }
231 } 237 }
232 238
233 private: 239 private:
234 static const int kInitialCapacity = 16; 240 static const int kInitialCapacity = 16;
235 static const int kGrowthFactory = 4; 241 static const int kGrowthFactory = 4;
236 static const int kMinConversionSlack = 256; 242 static const int kMinConversionSlack = 256;
237 static const int kMaxGrowth = 1 * MB; 243 static const int kMaxGrowth = 1 * MB;
238 inline int NewCapacity(int min_capacity) { 244 inline int NewCapacity(int min_capacity) {
239 int capacity = Max(min_capacity, backing_store_.length()); 245 int capacity = Max(min_capacity, backing_store_.length());
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 bool allow_harmony_exponentiation_operator_; 793 bool allow_harmony_exponentiation_operator_;
788 794
789 MessageTemplate::Template scanner_error_; 795 MessageTemplate::Template scanner_error_;
790 Location scanner_error_location_; 796 Location scanner_error_location_;
791 }; 797 };
792 798
793 } // namespace internal 799 } // namespace internal
794 } // namespace v8 800 } // namespace v8
795 801
796 #endif // V8_PARSING_SCANNER_H_ 802 #endif // V8_PARSING_SCANNER_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