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

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: A few changes after short review by antonm. 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 178
179 bool Object::IsConsString() { 179 bool Object::IsConsString() {
180 if (!this->IsHeapObject()) return false; 180 if (!this->IsHeapObject()) return false;
181 uint32_t type = HeapObject::cast(this)->map()->instance_type(); 181 uint32_t type = HeapObject::cast(this)->map()->instance_type();
182 return (type & (kIsNotStringMask | kStringRepresentationMask)) == 182 return (type & (kIsNotStringMask | kStringRepresentationMask)) ==
183 (kStringTag | kConsStringTag); 183 (kStringTag | kConsStringTag);
184 } 184 }
185 185
186 186
187 bool Object::IsSlicedString() {
188 if (!this->IsHeapObject()) return false;
189 uint32_t type = HeapObject::cast(this)->map()->instance_type();
190 uint32_t representation =
antonm 2011/07/27 14:04:49 if you don't want to introduce helper function whi
191 type & (kIsNotStringMask | kStringRepresentationMask);
192 return representation == (kStringTag | kSlicedStringTag);
193 }
194
195
187 bool Object::IsSeqString() { 196 bool Object::IsSeqString() {
188 if (!IsString()) return false; 197 if (!IsString()) return false;
189 return StringShape(String::cast(this)).IsSequential(); 198 return StringShape(String::cast(this)).IsSequential();
190 } 199 }
191 200
192 201
193 bool Object::IsSeqAsciiString() { 202 bool Object::IsSeqAsciiString() {
194 if (!IsString()) return false; 203 if (!IsString()) return false;
195 return StringShape(String::cast(this)).IsSequential() && 204 return StringShape(String::cast(this)).IsSequential() &&
196 String::cast(this)->IsAsciiRepresentation(); 205 String::cast(this)->IsAsciiRepresentation();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return (type & kStringEncodingMask) == kAsciiStringTag || 282 return (type & kStringEncodingMask) == kAsciiStringTag ||
274 (type & kAsciiDataHintMask) == kAsciiDataHintTag; 283 (type & kAsciiDataHintMask) == kAsciiDataHintTag;
275 } 284 }
276 285
277 286
278 bool StringShape::IsCons() { 287 bool StringShape::IsCons() {
279 return (type_ & kStringRepresentationMask) == kConsStringTag; 288 return (type_ & kStringRepresentationMask) == kConsStringTag;
280 } 289 }
281 290
282 291
292 bool StringShape::IsSliced() {
293 return (type_ & kStringRepresentationMask) == kSlicedStringTag;
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); 2164 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index);
2150 case kSeqStringTag | kTwoByteStringTag: 2165 case kSeqStringTag | kTwoByteStringTag:
2151 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); 2166 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
2152 case kConsStringTag | kAsciiStringTag: 2167 case kConsStringTag | kAsciiStringTag:
2153 case kConsStringTag | kTwoByteStringTag: 2168 case kConsStringTag | kTwoByteStringTag:
2154 return ConsString::cast(this)->ConsStringGet(index); 2169 return ConsString::cast(this)->ConsStringGet(index);
2155 case kExternalStringTag | kAsciiStringTag: 2170 case kExternalStringTag | kAsciiStringTag:
2156 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); 2171 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index);
2157 case kExternalStringTag | kTwoByteStringTag: 2172 case kExternalStringTag | kTwoByteStringTag:
2158 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 2173 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
2174 case kSlicedStringTag | kAsciiStringTag:
2175 case kSlicedStringTag | kTwoByteStringTag:
2176 return SlicedString::cast(this)->SlicedStringGet(index);
2159 default: 2177 default:
2160 break; 2178 break;
2161 } 2179 }
2162 2180
2163 UNREACHABLE(); 2181 UNREACHABLE();
2164 return 0; 2182 return 0;
2165 } 2183 }
2166 2184
2167 2185
2168 void String::Set(int index, uint16_t value) { 2186 void String::Set(int index, uint16_t value) {
(...skipping 12 matching lines...) Expand all
2181 String* second = ConsString::cast(this)->second(); 2199 String* second = ConsString::cast(this)->second();
2182 // Only flattened strings have second part empty. 2200 // Only flattened strings have second part empty.
2183 return second->length() == 0; 2201 return second->length() == 0;
2184 } 2202 }
2185 default: 2203 default:
2186 return true; 2204 return true;
2187 } 2205 }
2188 } 2206 }
2189 2207
2190 2208
2209 bool String::IsIndirect() {
2210 uint32_t representation = StringShape(this).representation_tag();
2211 return (representation & kIsIndirectStringMask) == kIsIndirectStringTag;
2212 }
2213
2214
2191 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { 2215 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) {
2192 ASSERT(index >= 0 && index < length()); 2216 ASSERT(index >= 0 && index < length());
2193 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); 2217 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
2194 } 2218 }
2195 2219
2196 2220
2197 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { 2221 void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) {
2198 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); 2222 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode);
2199 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, 2223 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize,
2200 static_cast<byte>(value)); 2224 static_cast<byte>(value));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { 2260 int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) {
2237 return SizeFor(length()); 2261 return SizeFor(length());
2238 } 2262 }
2239 2263
2240 2264
2241 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { 2265 int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) {
2242 return SizeFor(length()); 2266 return SizeFor(length());
2243 } 2267 }
2244 2268
2245 2269
2270 String* SlicedString::parent() {
2271 return String::cast(READ_FIELD(this, kParentOffset));
2272 }
2273
2274
2275 void SlicedString::set_parent(String* parent) {
2276 ASSERT(parent->IsSeqString());
2277 WRITE_FIELD(this, kParentOffset, parent);
2278 }
2279
2280
2281 SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
2282
2283
2246 String* ConsString::first() { 2284 String* ConsString::first() {
2247 return String::cast(READ_FIELD(this, kFirstOffset)); 2285 return String::cast(READ_FIELD(this, kFirstOffset));
2248 } 2286 }
2249 2287
2250 2288
2251 Object* ConsString::unchecked_first() { 2289 Object* ConsString::unchecked_first() {
2252 return READ_FIELD(this, kFirstOffset); 2290 return READ_FIELD(this, kFirstOffset);
2253 } 2291 }
2254 2292
2255 2293
(...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 #undef WRITE_INT_FIELD 4549 #undef WRITE_INT_FIELD
4512 #undef READ_SHORT_FIELD 4550 #undef READ_SHORT_FIELD
4513 #undef WRITE_SHORT_FIELD 4551 #undef WRITE_SHORT_FIELD
4514 #undef READ_BYTE_FIELD 4552 #undef READ_BYTE_FIELD
4515 #undef WRITE_BYTE_FIELD 4553 #undef WRITE_BYTE_FIELD
4516 4554
4517 4555
4518 } } // namespace v8::internal 4556 } } // namespace v8::internal
4519 4557
4520 #endif // V8_OBJECTS_INL_H_ 4558 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | src/objects-visiting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698