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

Side by Side Diff: src/objects-inl.h

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Included Vitaly's suggestions. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // Because the symbol tag is non-zero and no non-string types have the 170 // Because the symbol tag is non-zero and no non-string types have the
171 // symbol bit set we can test for symbols with a very simple test 171 // symbol bit set we can test for symbols with a very simple test
172 // operation. 172 // operation.
173 ASSERT(kSymbolTag != 0); 173 ASSERT(kSymbolTag != 0);
174 ASSERT(kNotStringTag + kIsSymbolMask > LAST_TYPE); 174 ASSERT(kNotStringTag + kIsSymbolMask > LAST_TYPE);
175 return (type & kIsSymbolMask) != 0; 175 return (type & kIsSymbolMask) != 0;
176 } 176 }
177 177
178 178
179 bool Object::IsConsString() { 179 bool Object::IsConsString() {
180 if (!this->IsHeapObject()) return false; 180 if (!IsString()) return false;
181 uint32_t type = HeapObject::cast(this)->map()->instance_type(); 181 return StringShape(String::cast(this)).IsCons();
182 return (type & (kIsNotStringMask | kStringRepresentationMask)) ==
183 (kStringTag | kConsStringTag);
184 } 182 }
185 183
186 184
185 bool Object::IsSlicedString() {
186 if (!IsString()) return false;
187 return StringShape(String::cast(this)).IsSliced();
188 }
189
190
187 bool Object::IsSeqString() { 191 bool Object::IsSeqString() {
188 if (!IsString()) return false; 192 if (!IsString()) return false;
189 return StringShape(String::cast(this)).IsSequential(); 193 return StringShape(String::cast(this)).IsSequential();
190 } 194 }
191 195
192 196
193 bool Object::IsSeqAsciiString() { 197 bool Object::IsSeqAsciiString() {
194 if (!IsString()) return false; 198 if (!IsString()) return false;
195 return StringShape(String::cast(this)).IsSequential() && 199 return StringShape(String::cast(this)).IsSequential() &&
196 String::cast(this)->IsAsciiRepresentation(); 200 String::cast(this)->IsAsciiRepresentation();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return (type & kStringEncodingMask) == kAsciiStringTag || 277 return (type & kStringEncodingMask) == kAsciiStringTag ||
274 (type & kAsciiDataHintMask) == kAsciiDataHintTag; 278 (type & kAsciiDataHintMask) == kAsciiDataHintTag;
275 } 279 }
276 280
277 281
278 bool StringShape::IsCons() { 282 bool StringShape::IsCons() {
279 return (type_ & kStringRepresentationMask) == kConsStringTag; 283 return (type_ & kStringRepresentationMask) == kConsStringTag;
280 } 284 }
281 285
282 286
287 bool StringShape::IsSliced() {
288 return (type_ & kStringRepresentationMask) == kSlicedStringTag;
289 }
290
291
292 bool StringShape::IsIndirect() {
293 return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag;
294 }
295
296
283 bool StringShape::IsExternal() { 297 bool StringShape::IsExternal() {
284 return (type_ & kStringRepresentationMask) == kExternalStringTag; 298 return (type_ & kStringRepresentationMask) == kExternalStringTag;
285 } 299 }
286 300
287 301
288 bool StringShape::IsSequential() { 302 bool StringShape::IsSequential() {
289 return (type_ & kStringRepresentationMask) == kSeqStringTag; 303 return (type_ & kStringRepresentationMask) == kSeqStringTag;
290 } 304 }
291 305
292 306
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 CAST_ACCESSOR(JSFunctionResultCache) 2048 CAST_ACCESSOR(JSFunctionResultCache)
2035 CAST_ACCESSOR(NormalizedMapCache) 2049 CAST_ACCESSOR(NormalizedMapCache)
2036 CAST_ACCESSOR(CompilationCacheTable) 2050 CAST_ACCESSOR(CompilationCacheTable)
2037 CAST_ACCESSOR(CodeCacheHashTable) 2051 CAST_ACCESSOR(CodeCacheHashTable)
2038 CAST_ACCESSOR(PolymorphicCodeCacheHashTable) 2052 CAST_ACCESSOR(PolymorphicCodeCacheHashTable)
2039 CAST_ACCESSOR(MapCache) 2053 CAST_ACCESSOR(MapCache)
2040 CAST_ACCESSOR(String) 2054 CAST_ACCESSOR(String)
2041 CAST_ACCESSOR(SeqString) 2055 CAST_ACCESSOR(SeqString)
2042 CAST_ACCESSOR(SeqAsciiString) 2056 CAST_ACCESSOR(SeqAsciiString)
2043 CAST_ACCESSOR(SeqTwoByteString) 2057 CAST_ACCESSOR(SeqTwoByteString)
2058 CAST_ACCESSOR(SlicedString)
2044 CAST_ACCESSOR(ConsString) 2059 CAST_ACCESSOR(ConsString)
2045 CAST_ACCESSOR(ExternalString) 2060 CAST_ACCESSOR(ExternalString)
2046 CAST_ACCESSOR(ExternalAsciiString) 2061 CAST_ACCESSOR(ExternalAsciiString)
2047 CAST_ACCESSOR(ExternalTwoByteString) 2062 CAST_ACCESSOR(ExternalTwoByteString)
2048 CAST_ACCESSOR(JSReceiver) 2063 CAST_ACCESSOR(JSReceiver)
2049 CAST_ACCESSOR(JSObject) 2064 CAST_ACCESSOR(JSObject)
2050 CAST_ACCESSOR(Smi) 2065 CAST_ACCESSOR(Smi)
2051 CAST_ACCESSOR(HeapObject) 2066 CAST_ACCESSOR(HeapObject)
2052 CAST_ACCESSOR(HeapNumber) 2067 CAST_ACCESSOR(HeapNumber)
2053 CAST_ACCESSOR(Oddball) 2068 CAST_ACCESSOR(Oddball)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 if (StringShape(this).IsSymbol() && StringShape(other).IsSymbol()) { 2135 if (StringShape(this).IsSymbol() && StringShape(other).IsSymbol()) {
2121 return false; 2136 return false;
2122 } 2137 }
2123 return SlowEquals(other); 2138 return SlowEquals(other);
2124 } 2139 }
2125 2140
2126 2141
2127 MaybeObject* String::TryFlatten(PretenureFlag pretenure) { 2142 MaybeObject* String::TryFlatten(PretenureFlag pretenure) {
2128 if (!StringShape(this).IsCons()) return this; 2143 if (!StringShape(this).IsCons()) return this;
2129 ConsString* cons = ConsString::cast(this); 2144 ConsString* cons = ConsString::cast(this);
2130 if (cons->second()->length() == 0) return cons->first(); 2145 if (cons->IsFlat()) return cons->first();
2131 return SlowTryFlatten(pretenure); 2146 return SlowTryFlatten(pretenure);
2132 } 2147 }
2133 2148
2134 2149
2135 String* String::TryFlattenGetString(PretenureFlag pretenure) { 2150 String* String::TryFlattenGetString(PretenureFlag pretenure) {
2136 MaybeObject* flat = TryFlatten(pretenure); 2151 MaybeObject* flat = TryFlatten(pretenure);
2137 Object* successfully_flattened; 2152 Object* successfully_flattened;
2138 if (flat->ToObject(&successfully_flattened)) { 2153 if (!flat->ToObject(&successfully_flattened)) return this;
2139 return String::cast(successfully_flattened); 2154 return String::cast(successfully_flattened);
2140 }
2141 return this;
2142 } 2155 }
2143 2156
2144 2157
2145 uint16_t String::Get(int index) { 2158 uint16_t String::Get(int index) {
2146 ASSERT(index >= 0 && index < length()); 2159 ASSERT(index >= 0 && index < length());
2147 switch (StringShape(this).full_representation_tag()) { 2160 switch (StringShape(this).full_representation_tag()) {
2148 case kSeqStringTag | kAsciiStringTag: 2161 case kSeqStringTag | kAsciiStringTag:
2149 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); 2162 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index);
2150 case kSeqStringTag | kTwoByteStringTag: 2163 case kSeqStringTag | kTwoByteStringTag:
2151 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 2164 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
2152 case kConsStringTag | kAsciiStringTag: 2165 case kConsStringTag | kAsciiStringTag:
2153 case kConsStringTag | kTwoByteStringTag: 2166 case kConsStringTag | kTwoByteStringTag:
2154 return ConsString::cast(this)->ConsStringGet(index); 2167 return ConsString::cast(this)->ConsStringGet(index);
2155 case kExternalStringTag | kAsciiStringTag: 2168 case kExternalStringTag | kAsciiStringTag:
2156 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); 2169 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index);
2157 case kExternalStringTag | kTwoByteStringTag: 2170 case kExternalStringTag | kTwoByteStringTag:
2158 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 2171 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
2172 case kSlicedStringTag | kAsciiStringTag:
2173 case kSlicedStringTag | kTwoByteStringTag:
2174 return SlicedString::cast(this)->SlicedStringGet(index);
2159 default: 2175 default:
2160 break; 2176 break;
2161 } 2177 }
2162 2178
2163 UNREACHABLE(); 2179 UNREACHABLE();
2164 return 0; 2180 return 0;
2165 } 2181 }
2166 2182
2167 2183
2168 void String::Set(int index, uint16_t value) { 2184 void String::Set(int index, uint16_t value) {
2169 ASSERT(index >= 0 && index < length()); 2185 ASSERT(index >= 0 && index < length());
2170 ASSERT(StringShape(this).IsSequential()); 2186 ASSERT(StringShape(this).IsSequential());
2171 2187
2172 return this->IsAsciiRepresentation() 2188 return this->IsAsciiRepresentation()
2173 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) 2189 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value)
2174 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); 2190 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value);
2175 } 2191 }
2176 2192
2177 2193
2178 bool String::IsFlat() { 2194 bool String::IsFlat() {
2179 switch (StringShape(this).representation_tag()) { 2195 if (!StringShape(this).IsCons()) return true;
2180 case kConsStringTag: { 2196 return ConsString::cast(this)->second() == GetHeap()->empty_string();
Vitaly Repeshko 2011/08/17 19:20:23 Length check is probably a tiny bit faster as GetH
2181 String* second = ConsString::cast(this)->second();
2182 // Only flattened strings have second part empty.
2183 return second->length() == 0;
2184 }
2185 default:
2186 return true;
2187 }
2188 } 2197 }
2189 2198
2190 2199
2200 String* String::GetIndirect() {
2201 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset);
2202 // Giving direct access to underlying string only makes sense if the
2203 // wrapping string is already flattened.
2204 ASSERT(this->IsFlat());
2205 ASSERT(StringShape(this).IsIndirect());
2206 return String::cast(reinterpret_cast<ConsString*>(this)->first());
Vitaly Repeshko 2011/08/17 19:20:23 Doesn't work as advertised in the .h file. It shou
2207 }
2208
2209
2191 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { 2210 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) {
2192 ASSERT(index >= 0 && index < length()); 2211 ASSERT(index >= 0 && index < length());
2193 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); 2212 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
2194 } 2213 }
2195 2214
2196 2215
2197 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { 2216 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) {
2198 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); 2217 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode);
2199 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, 2218 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize,
2200 static_cast<byte>(value)); 2219 static_cast<byte>(value));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { 2255 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) {
2237 return SizeFor(length()); 2256 return SizeFor(length());
2238 } 2257 }
2239 2258
2240 2259
2241 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { 2260 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) {
2242 return SizeFor(length()); 2261 return SizeFor(length());
2243 } 2262 }
2244 2263
2245 2264
2265 String* SlicedString::parent() {
2266 return String::cast(READ_FIELD(this, kParentOffset));
2267 }
2268
2269
2270 void SlicedString::set_parent(String* parent) {
2271 ASSERT(parent->IsSeqString());
2272 WRITE_FIELD(this, kParentOffset, parent);
2273 }
2274
2275
2276 SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
2277
2278
2246 String* ConsString::first() { 2279 String* ConsString::first() {
2247 return String::cast(READ_FIELD(this, kFirstOffset)); 2280 return String::cast(READ_FIELD(this, kFirstOffset));
2248 } 2281 }
2249 2282
2250 2283
2251 Object* ConsString::unchecked_first() { 2284 Object* ConsString::unchecked_first() {
2252 return READ_FIELD(this, kFirstOffset); 2285 return READ_FIELD(this, kFirstOffset);
2253 } 2286 }
2254 2287
2255 2288
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 #undef WRITE_INT_FIELD 4544 #undef WRITE_INT_FIELD
4512 #undef READ_SHORT_FIELD 4545 #undef READ_SHORT_FIELD
4513 #undef WRITE_SHORT_FIELD 4546 #undef WRITE_SHORT_FIELD
4514 #undef READ_BYTE_FIELD 4547 #undef READ_BYTE_FIELD
4515 #undef WRITE_BYTE_FIELD 4548 #undef WRITE_BYTE_FIELD
4516 4549
4517 4550
4518 } } // namespace v8::internal 4551 } } // namespace v8::internal
4519 4552
4520 #endif // V8_OBJECTS_INL_H_ 4553 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects-debug.cc ('K') | « src/objects-debug.cc ('k') | src/objects-visiting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698