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

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: Addressed some of the things pointed out by Anton. 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
283 bool StringShape::IsExternal() { 292 bool StringShape::IsExternal() {
284 return (type_ & kStringRepresentationMask) == kExternalStringTag; 293 return (type_ & kStringRepresentationMask) == kExternalStringTag;
285 } 294 }
286 295
287 296
288 bool StringShape::IsSequential() { 297 bool StringShape::IsSequential() {
289 return (type_ & kStringRepresentationMask) == kSeqStringTag; 298 return (type_ & kStringRepresentationMask) == kSeqStringTag;
290 } 299 }
291 300
292 301
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 CAST_ACCESSOR(JSFunctionResultCache) 2043 CAST_ACCESSOR(JSFunctionResultCache)
2035 CAST_ACCESSOR(NormalizedMapCache) 2044 CAST_ACCESSOR(NormalizedMapCache)
2036 CAST_ACCESSOR(CompilationCacheTable) 2045 CAST_ACCESSOR(CompilationCacheTable)
2037 CAST_ACCESSOR(CodeCacheHashTable) 2046 CAST_ACCESSOR(CodeCacheHashTable)
2038 CAST_ACCESSOR(PolymorphicCodeCacheHashTable) 2047 CAST_ACCESSOR(PolymorphicCodeCacheHashTable)
2039 CAST_ACCESSOR(MapCache) 2048 CAST_ACCESSOR(MapCache)
2040 CAST_ACCESSOR(String) 2049 CAST_ACCESSOR(String)
2041 CAST_ACCESSOR(SeqString) 2050 CAST_ACCESSOR(SeqString)
2042 CAST_ACCESSOR(SeqAsciiString) 2051 CAST_ACCESSOR(SeqAsciiString)
2043 CAST_ACCESSOR(SeqTwoByteString) 2052 CAST_ACCESSOR(SeqTwoByteString)
2053 CAST_ACCESSOR(SlicedString)
2044 CAST_ACCESSOR(ConsString) 2054 CAST_ACCESSOR(ConsString)
2045 CAST_ACCESSOR(ExternalString) 2055 CAST_ACCESSOR(ExternalString)
2046 CAST_ACCESSOR(ExternalAsciiString) 2056 CAST_ACCESSOR(ExternalAsciiString)
2047 CAST_ACCESSOR(ExternalTwoByteString) 2057 CAST_ACCESSOR(ExternalTwoByteString)
2048 CAST_ACCESSOR(JSReceiver) 2058 CAST_ACCESSOR(JSReceiver)
2049 CAST_ACCESSOR(JSObject) 2059 CAST_ACCESSOR(JSObject)
2050 CAST_ACCESSOR(Smi) 2060 CAST_ACCESSOR(Smi)
2051 CAST_ACCESSOR(HeapObject) 2061 CAST_ACCESSOR(HeapObject)
2052 CAST_ACCESSOR(HeapNumber) 2062 CAST_ACCESSOR(HeapNumber)
2053 CAST_ACCESSOR(Oddball) 2063 CAST_ACCESSOR(Oddball)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); 2159 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index);
2150 case kSeqStringTag | kTwoByteStringTag: 2160 case kSeqStringTag | kTwoByteStringTag:
2151 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 2161 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
2152 case kConsStringTag | kAsciiStringTag: 2162 case kConsStringTag | kAsciiStringTag:
2153 case kConsStringTag | kTwoByteStringTag: 2163 case kConsStringTag | kTwoByteStringTag:
2154 return ConsString::cast(this)->ConsStringGet(index); 2164 return ConsString::cast(this)->ConsStringGet(index);
2155 case kExternalStringTag | kAsciiStringTag: 2165 case kExternalStringTag | kAsciiStringTag:
2156 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); 2166 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index);
2157 case kExternalStringTag | kTwoByteStringTag: 2167 case kExternalStringTag | kTwoByteStringTag:
2158 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 2168 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
2169 case kSlicedStringTag | kAsciiStringTag:
2170 case kSlicedStringTag | kTwoByteStringTag:
2171 return SlicedString::cast(this)->SlicedStringGet(index);
2159 default: 2172 default:
2160 break; 2173 break;
2161 } 2174 }
2162 2175
2163 UNREACHABLE(); 2176 UNREACHABLE();
2164 return 0; 2177 return 0;
2165 } 2178 }
2166 2179
2167 2180
2168 void String::Set(int index, uint16_t value) { 2181 void String::Set(int index, uint16_t value) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { 2249 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) {
2237 return SizeFor(length()); 2250 return SizeFor(length());
2238 } 2251 }
2239 2252
2240 2253
2241 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { 2254 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) {
2242 return SizeFor(length()); 2255 return SizeFor(length());
2243 } 2256 }
2244 2257
2245 2258
2259 String* SlicedString::parent() {
2260 return String::cast(READ_FIELD(this, kParentOffset));
2261 }
2262
2263
2264 void SlicedString::set_parent(String* parent) {
2265 ASSERT(parent->IsSeqString());
2266 WRITE_FIELD(this, kParentOffset, parent);
2267 }
2268
2269
2270 SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
2271
2272
2246 String* ConsString::first() { 2273 String* ConsString::first() {
2247 return String::cast(READ_FIELD(this, kFirstOffset)); 2274 return String::cast(READ_FIELD(this, kFirstOffset));
2248 } 2275 }
2249 2276
2250 2277
2251 Object* ConsString::unchecked_first() { 2278 Object* ConsString::unchecked_first() {
2252 return READ_FIELD(this, kFirstOffset); 2279 return READ_FIELD(this, kFirstOffset);
2253 } 2280 }
2254 2281
2255 2282
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 #undef WRITE_INT_FIELD 4538 #undef WRITE_INT_FIELD
4512 #undef READ_SHORT_FIELD 4539 #undef READ_SHORT_FIELD
4513 #undef WRITE_SHORT_FIELD 4540 #undef WRITE_SHORT_FIELD
4514 #undef READ_BYTE_FIELD 4541 #undef READ_BYTE_FIELD
4515 #undef WRITE_BYTE_FIELD 4542 #undef WRITE_BYTE_FIELD
4516 4543
4517 4544
4518 } } // namespace v8::internal 4545 } } // namespace v8::internal
4519 4546
4520 #endif // V8_OBJECTS_INL_H_ 4547 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/objects-visiting.h » ('j') | test/mjsunit/string-slices.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698