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

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

Issue 2220363002: De-virtualize AstString. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rearranging Created 4 years, 4 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 | « src/ast/ast-value-factory.h ('k') | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 }; 51 };
52 52
53 } // namespace 53 } // namespace
54 54
55 class AstRawStringInternalizationKey : public HashTableKey { 55 class AstRawStringInternalizationKey : public HashTableKey {
56 public: 56 public:
57 explicit AstRawStringInternalizationKey(const AstRawString* string) 57 explicit AstRawStringInternalizationKey(const AstRawString* string)
58 : string_(string) {} 58 : string_(string) {}
59 59
60 bool IsMatch(Object* other) override { 60 bool IsMatch(Object* other) override {
61 if (string_->is_one_byte_) 61 if (string_->is_one_byte())
62 return String::cast(other)->IsOneByteEqualTo(string_->literal_bytes_); 62 return String::cast(other)->IsOneByteEqualTo(string_->literal_bytes_);
63 return String::cast(other)->IsTwoByteEqualTo( 63 return String::cast(other)->IsTwoByteEqualTo(
64 Vector<const uint16_t>::cast(string_->literal_bytes_)); 64 Vector<const uint16_t>::cast(string_->literal_bytes_));
65 } 65 }
66 66
67 uint32_t Hash() override { return string_->hash() >> Name::kHashShift; } 67 uint32_t Hash() override { return string_->hash() >> Name::kHashShift; }
68 68
69 uint32_t HashForObject(Object* key) override { 69 uint32_t HashForObject(Object* key) override {
70 return String::cast(key)->Hash(); 70 return String::cast(key)->Hash();
71 } 71 }
72 72
73 Handle<Object> AsHandle(Isolate* isolate) override { 73 Handle<Object> AsHandle(Isolate* isolate) override {
74 if (string_->is_one_byte_) 74 if (string_->is_one_byte())
75 return isolate->factory()->NewOneByteInternalizedString( 75 return isolate->factory()->NewOneByteInternalizedString(
76 string_->literal_bytes_, string_->hash()); 76 string_->literal_bytes_, string_->hash());
77 return isolate->factory()->NewTwoByteInternalizedString( 77 return isolate->factory()->NewTwoByteInternalizedString(
78 Vector<const uint16_t>::cast(string_->literal_bytes_), string_->hash()); 78 Vector<const uint16_t>::cast(string_->literal_bytes_), string_->hash());
79 } 79 }
80 80
81 private: 81 private:
82 const AstRawString* string_; 82 const AstRawString* string_;
83 }; 83 };
84 84
85 int AstString::length() const {
86 if (IsRawStringBits::decode(bit_field_)) {
87 return reinterpret_cast<const AstRawString*>(this)->length();
88 }
89 return reinterpret_cast<const AstConsString*>(this)->length();
90 }
91
92 void AstString::Internalize(Isolate* isolate) {
93 if (IsRawStringBits::decode(bit_field_)) {
94 return reinterpret_cast<AstRawString*>(this)->Internalize(isolate);
95 }
96 return reinterpret_cast<AstConsString*>(this)->Internalize(isolate);
97 }
85 98
86 void AstRawString::Internalize(Isolate* isolate) { 99 void AstRawString::Internalize(Isolate* isolate) {
87 if (!string_.is_null()) return; 100 if (!string_.is_null()) return;
88 if (literal_bytes_.length() == 0) { 101 if (literal_bytes_.length() == 0) {
89 string_ = isolate->factory()->empty_string(); 102 string_ = isolate->factory()->empty_string();
90 } else { 103 } else {
91 AstRawStringInternalizationKey key(this); 104 AstRawStringInternalizationKey key(this);
92 string_ = StringTable::LookupKey(isolate, &key); 105 string_ = StringTable::LookupKey(isolate, &key);
93 } 106 }
94 } 107 }
95 108
96 109
97 bool AstRawString::AsArrayIndex(uint32_t* index) const { 110 bool AstRawString::AsArrayIndex(uint32_t* index) const {
98 if (!string_.is_null()) 111 if (!string_.is_null())
99 return string_->AsArrayIndex(index); 112 return string_->AsArrayIndex(index);
100 if (!is_one_byte_ || literal_bytes_.length() == 0 || 113 if (!is_one_byte() || literal_bytes_.length() == 0 ||
101 literal_bytes_.length() > String::kMaxArrayIndexSize) 114 literal_bytes_.length() > String::kMaxArrayIndexSize)
102 return false; 115 return false;
103 OneByteStringStream stream(literal_bytes_); 116 OneByteStringStream stream(literal_bytes_);
104 return StringToArrayIndex(&stream, index); 117 return StringToArrayIndex(&stream, index);
105 } 118 }
106 119
107 120
108 bool AstRawString::IsOneByteEqualTo(const char* data) const { 121 bool AstRawString::IsOneByteEqualTo(const char* data) const {
109 int length = static_cast<int>(strlen(data)); 122 int length = static_cast<int>(strlen(data));
110 if (is_one_byte_ && literal_bytes_.length() == length) { 123 if (is_one_byte() && literal_bytes_.length() == length) {
111 const char* token = reinterpret_cast<const char*>(literal_bytes_.start()); 124 const char* token = reinterpret_cast<const char*>(literal_bytes_.start());
112 return !strncmp(token, data, length); 125 return !strncmp(token, data, length);
113 } 126 }
114 return false; 127 return false;
115 } 128 }
116 129
117 130
118 void AstConsString::Internalize(Isolate* isolate) { 131 void AstConsString::Internalize(Isolate* isolate) {
119 // AstRawStrings are internalized before AstConsStrings so left and right are 132 // AstRawStrings are internalized before AstConsStrings so left and right are
120 // already internalized. 133 // already internalized.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 length) == 0; 419 length) == 0;
407 } else { 420 } else {
408 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), 421 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
409 reinterpret_cast<const uint16_t*>(r), 422 reinterpret_cast<const uint16_t*>(r),
410 length) == 0; 423 length) == 0;
411 } 424 }
412 } 425 }
413 } 426 }
414 } // namespace internal 427 } // namespace internal
415 } // namespace v8 428 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast-value-factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698