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

Side by Side Diff: src/ast/ast-value-factory.h

Issue 1511363002: Make AstConsString::length constant-time instead of O(N) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 DCHECK(!string_.is_null()); 55 DCHECK(!string_.is_null());
56 return string_; 56 return string_;
57 } 57 }
58 58
59 protected: 59 protected:
60 // This is null until the string is internalized. 60 // This is null until the string is internalized.
61 Handle<String> string_; 61 Handle<String> string_;
62 }; 62 };
63 63
64 64
65 class AstRawString : public AstString { 65 class AstRawString final : public AstString {
66 public: 66 public:
67 int length() const override { 67 int length() const override {
68 if (is_one_byte_) 68 if (is_one_byte_)
69 return literal_bytes_.length(); 69 return literal_bytes_.length();
70 return literal_bytes_.length() / 2; 70 return literal_bytes_.length() / 2;
71 } 71 }
72 72
73 int byte_length() const { return literal_bytes_.length(); } 73 int byte_length() const { return literal_bytes_.length(); }
74 74
75 void Internalize(Isolate* isolate) override; 75 void Internalize(Isolate* isolate) override;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 hash_(0) {} 108 hash_(0) {}
109 109
110 bool is_one_byte_; 110 bool is_one_byte_;
111 111
112 // Points to memory owned by Zone. 112 // Points to memory owned by Zone.
113 Vector<const byte> literal_bytes_; 113 Vector<const byte> literal_bytes_;
114 uint32_t hash_; 114 uint32_t hash_;
115 }; 115 };
116 116
117 117
118 class AstConsString : public AstString { 118 class AstConsString final : public AstString {
119 public: 119 public:
120 AstConsString(const AstString* left, const AstString* right) 120 AstConsString(const AstString* left, const AstString* right)
121 : left_(left), 121 : length_(left->length() + right->length()), left_(left), right_(right) {}
122 right_(right) {}
123 122
124 int length() const override { return left_->length() + right_->length(); } 123 int length() const override { return length_; }
125 124
126 void Internalize(Isolate* isolate) override; 125 void Internalize(Isolate* isolate) override;
127 126
128 private: 127 private:
129 friend class AstValueFactory; 128 const int length_;
130
131 const AstString* left_; 129 const AstString* left_;
132 const AstString* right_; 130 const AstString* right_;
133 }; 131 };
134 132
135 133
136 // AstValue is either a string, a number, a string array, a boolean, or a 134 // AstValue is either a string, a number, a string array, a boolean, or a
137 // special value (null, undefined, the hole). 135 // special value (null, undefined, the hole).
138 class AstValue : public ZoneObject { 136 class AstValue : public ZoneObject {
139 public: 137 public:
140 bool IsString() const { 138 bool IsString() const {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 OTHER_CONSTANTS(F) 363 OTHER_CONSTANTS(F)
366 #undef F 364 #undef F
367 }; 365 };
368 } // namespace internal 366 } // namespace internal
369 } // namespace v8 367 } // namespace v8
370 368
371 #undef STRING_CONSTANTS 369 #undef STRING_CONSTANTS
372 #undef OTHER_CONSTANTS 370 #undef OTHER_CONSTANTS
373 371
374 #endif // V8_AST_AST_VALUE_FACTORY_H_ 372 #endif // V8_AST_AST_VALUE_FACTORY_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