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

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: Implemented some changes suggested 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
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
2158 MaybeObject* String::TryTruncate(PretenureFlag pretenure) {
2159 if (!StringShape(this).IsSliced()) return this;
2160 SlicedString* slice = SlicedString::cast(this);
2161 if (slice->IsTruncated()) return slice->parent();
2162 return SlowTryTruncate(pretenure);
2163 }
2164
2165
2166 String* String::TryTruncateGetString(PretenureFlag pretenure) {
2167 MaybeObject* truncate = TryTruncate(pretenure);
2168 Object* successfully_truncated;
2169 if (!truncate->ToObject(&successfully_truncated)) return this;
2170 return String::cast(successfully_truncated);
2171 }
2172
2173
2174 MaybeObject* String::TryFlattenOrTruncate(PretenureFlag pretenure) {
2175 switch (StringShape(this).representation_tag()) {
2176 case kSlicedStringTag: {
2177 SlicedString* slice = SlicedString::cast(this);
2178 if (slice->IsTruncated()) return slice->parent();
2179 return SlowTryTruncate(pretenure);
2180 }
2181 case kConsStringTag: {
2182 ConsString* cons = ConsString::cast(this);
2183 if (cons->IsFlat()) return cons->first();
2184 return SlowTryFlatten(pretenure);
2185 }
2186 default:
2187 return this;
2188 }
2189 }
2190
2191
2145 uint16_t String::Get(int index) { 2192 uint16_t String::Get(int index) {
2146 ASSERT(index >= 0 && index < length()); 2193 ASSERT(index >= 0 && index < length());
2147 switch (StringShape(this).full_representation_tag()) { 2194 switch (StringShape(this).full_representation_tag()) {
2148 case kSeqStringTag | kAsciiStringTag: 2195 case kSeqStringTag | kAsciiStringTag:
2149 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); 2196 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index);
2150 case kSeqStringTag | kTwoByteStringTag: 2197 case kSeqStringTag | kTwoByteStringTag:
2151 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 2198 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
2152 case kConsStringTag | kAsciiStringTag: 2199 case kConsStringTag | kAsciiStringTag:
2153 case kConsStringTag | kTwoByteStringTag: 2200 case kConsStringTag | kTwoByteStringTag:
2154 return ConsString::cast(this)->ConsStringGet(index); 2201 return ConsString::cast(this)->ConsStringGet(index);
2155 case kExternalStringTag | kAsciiStringTag: 2202 case kExternalStringTag | kAsciiStringTag:
2156 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); 2203 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index);
2157 case kExternalStringTag | kTwoByteStringTag: 2204 case kExternalStringTag | kTwoByteStringTag:
2158 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 2205 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
2206 case kSlicedStringTag | kAsciiStringTag:
2207 case kSlicedStringTag | kTwoByteStringTag:
2208 return SlicedString::cast(this)->SlicedStringGet(index);
2159 default: 2209 default:
2160 break; 2210 break;
2161 } 2211 }
2162 2212
2163 UNREACHABLE(); 2213 UNREACHABLE();
2164 return 0; 2214 return 0;
2165 } 2215 }
2166 2216
2167 2217
2168 void String::Set(int index, uint16_t value) { 2218 void String::Set(int index, uint16_t value) {
2169 ASSERT(index >= 0 && index < length()); 2219 ASSERT(index >= 0 && index < length());
2170 ASSERT(StringShape(this).IsSequential()); 2220 ASSERT(StringShape(this).IsSequential());
2171 2221
2172 return this->IsAsciiRepresentation() 2222 return this->IsAsciiRepresentation()
2173 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) 2223 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value)
2174 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); 2224 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value);
2175 } 2225 }
2176 2226
2177 2227
2178 bool String::IsFlat() { 2228 bool String::IsFlat() {
2229 if (!StringShape(this).IsCons()) return true;
2230 return ConsString::cast(this)->second() == GetHeap()->empty_string();
2231 }
2232
2233
2234 bool String::IsTruncated() {
2235 if (!StringShape(this).IsSliced()) return true;
2236 SlicedString* slice = SlicedString::cast(this);
2237 return slice->parent()->length() == slice->length();
2238 }
2239
2240
2241 bool String::IsFlatAndTruncated() {
2179 switch (StringShape(this).representation_tag()) { 2242 switch (StringShape(this).representation_tag()) {
2180 case kConsStringTag: { 2243 case kSlicedStringTag: {
2181 String* second = ConsString::cast(this)->second(); 2244 SlicedString* slice = SlicedString::cast(this);
2182 // Only flattened strings have second part empty. 2245 return slice->parent()->length() == slice->length();
2183 return second->length() == 0;
2184 } 2246 }
2247 case kConsStringTag:
2248 return ConsString::cast(this)->second() == GetHeap()->empty_string();
2185 default: 2249 default:
2186 return true; 2250 return true;
2187 } 2251 }
2188 } 2252 }
2189 2253
2190 2254
2255 String* String::GetIndirect() {
2256 STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset);
2257 // Giving direct access to underlying string only makes sense if the
2258 // wrapping string is already flattened/truncated.
2259 ASSERT(this->IsFlat());
2260 ASSERT(this->IsTruncated());
2261 ASSERT(StringShape(this).IsIndirect());
2262 return String::cast(reinterpret_cast<ConsString*>(this)->first());
2263 }
2264
2265
2191 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { 2266 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) {
2192 ASSERT(index >= 0 && index < length()); 2267 ASSERT(index >= 0 && index < length());
2193 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); 2268 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
2194 } 2269 }
2195 2270
2196 2271
2197 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { 2272 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) {
2198 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); 2273 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode);
2199 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, 2274 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize,
2200 static_cast<byte>(value)); 2275 static_cast<byte>(value));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { 2311 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) {
2237 return SizeFor(length()); 2312 return SizeFor(length());
2238 } 2313 }
2239 2314
2240 2315
2241 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { 2316 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) {
2242 return SizeFor(length()); 2317 return SizeFor(length());
2243 } 2318 }
2244 2319
2245 2320
2321 String* SlicedString::parent() {
2322 return String::cast(READ_FIELD(this, kParentOffset));
2323 }
2324
2325
2326 void SlicedString::set_parent(String* parent) {
2327 ASSERT(parent->IsSeqString());
2328 WRITE_FIELD(this, kParentOffset, parent);
2329 }
2330
2331
2332 SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
2333
2334
2246 String* ConsString::first() { 2335 String* ConsString::first() {
2247 return String::cast(READ_FIELD(this, kFirstOffset)); 2336 return String::cast(READ_FIELD(this, kFirstOffset));
2248 } 2337 }
2249 2338
2250 2339
2251 Object* ConsString::unchecked_first() { 2340 Object* ConsString::unchecked_first() {
2252 return READ_FIELD(this, kFirstOffset); 2341 return READ_FIELD(this, kFirstOffset);
2253 } 2342 }
2254 2343
2255 2344
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 #undef WRITE_INT_FIELD 4600 #undef WRITE_INT_FIELD
4512 #undef READ_SHORT_FIELD 4601 #undef READ_SHORT_FIELD
4513 #undef WRITE_SHORT_FIELD 4602 #undef WRITE_SHORT_FIELD
4514 #undef READ_BYTE_FIELD 4603 #undef READ_BYTE_FIELD
4515 #undef WRITE_BYTE_FIELD 4604 #undef WRITE_BYTE_FIELD
4516 4605
4517 4606
4518 } } // namespace v8::internal 4607 } } // namespace v8::internal
4519 4608
4520 #endif // V8_OBJECTS_INL_H_ 4609 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.h ('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