OLD | NEW |
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 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 return READ_FIELD(this, kSecondOffset); | 2290 return READ_FIELD(this, kSecondOffset); |
2291 } | 2291 } |
2292 | 2292 |
2293 | 2293 |
2294 void ConsString::set_second(String* value, WriteBarrierMode mode) { | 2294 void ConsString::set_second(String* value, WriteBarrierMode mode) { |
2295 WRITE_FIELD(this, kSecondOffset, value); | 2295 WRITE_FIELD(this, kSecondOffset, value); |
2296 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); | 2296 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); |
2297 } | 2297 } |
2298 | 2298 |
2299 | 2299 |
2300 void ExternalString::clear_data_cache() { | 2300 bool ExternalString::is_short() { |
2301 WRITE_INTPTR_FIELD(this, kResourceDataOffset, 0); | 2301 InstanceType type = map()->instance_type(); |
| 2302 return (type & kShortExternalStringMask) == kShortExternalStringTag; |
2302 } | 2303 } |
2303 | 2304 |
2304 | 2305 |
2305 const ExternalAsciiString::Resource* ExternalAsciiString::resource() { | 2306 const ExternalAsciiString::Resource* ExternalAsciiString::resource() { |
2306 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); | 2307 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
2307 } | 2308 } |
2308 | 2309 |
2309 | 2310 |
| 2311 void ExternalAsciiString::update_data_cache() { |
| 2312 if (is_short()) return; |
| 2313 const char** data_field = |
| 2314 reinterpret_cast<const char**>(FIELD_ADDR(this, kResourceDataOffset)); |
| 2315 *data_field = resource()->data(); |
| 2316 } |
| 2317 |
| 2318 |
2310 void ExternalAsciiString::set_resource( | 2319 void ExternalAsciiString::set_resource( |
2311 const ExternalAsciiString::Resource* resource) { | 2320 const ExternalAsciiString::Resource* resource) { |
2312 *reinterpret_cast<const Resource**>( | 2321 *reinterpret_cast<const Resource**>( |
2313 FIELD_ADDR(this, kResourceOffset)) = resource; | 2322 FIELD_ADDR(this, kResourceOffset)) = resource; |
2314 clear_data_cache(); | 2323 if (resource != NULL) update_data_cache(); |
2315 } | 2324 } |
2316 | 2325 |
2317 | 2326 |
2318 const char* ExternalAsciiString::GetChars() { | 2327 const char* ExternalAsciiString::GetChars() { |
2319 const char** data_field = | 2328 return resource()->data(); |
2320 reinterpret_cast<const char**>(FIELD_ADDR(this, kResourceDataOffset)); | |
2321 if (*data_field == NULL) *data_field = resource()->data(); | |
2322 return *data_field; | |
2323 } | 2329 } |
2324 | 2330 |
2325 | 2331 |
2326 uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) { | 2332 uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) { |
2327 ASSERT(index >= 0 && index < length()); | 2333 ASSERT(index >= 0 && index < length()); |
2328 return GetChars()[index]; | 2334 return GetChars()[index]; |
2329 } | 2335 } |
2330 | 2336 |
2331 | 2337 |
2332 const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() { | 2338 const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() { |
2333 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); | 2339 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
2334 } | 2340 } |
2335 | 2341 |
2336 | 2342 |
| 2343 void ExternalTwoByteString::update_data_cache() { |
| 2344 if (is_short()) return; |
| 2345 const uint16_t** data_field = |
| 2346 reinterpret_cast<const uint16_t**>(FIELD_ADDR(this, kResourceDataOffset)); |
| 2347 *data_field = resource()->data(); |
| 2348 } |
| 2349 |
| 2350 |
2337 void ExternalTwoByteString::set_resource( | 2351 void ExternalTwoByteString::set_resource( |
2338 const ExternalTwoByteString::Resource* resource) { | 2352 const ExternalTwoByteString::Resource* resource) { |
2339 *reinterpret_cast<const Resource**>( | 2353 *reinterpret_cast<const Resource**>( |
2340 FIELD_ADDR(this, kResourceOffset)) = resource; | 2354 FIELD_ADDR(this, kResourceOffset)) = resource; |
2341 clear_data_cache(); | 2355 if (resource != NULL) update_data_cache(); |
2342 } | 2356 } |
2343 | 2357 |
2344 | 2358 |
2345 const uint16_t* ExternalTwoByteString::GetChars() { | 2359 const uint16_t* ExternalTwoByteString::GetChars() { |
2346 const uint16_t** data_field = | 2360 return resource()->data(); |
2347 reinterpret_cast<const uint16_t**>(FIELD_ADDR(this, kResourceDataOffset)); | |
2348 if (*data_field == NULL) *data_field = resource()->data(); | |
2349 return *data_field; | |
2350 } | 2361 } |
2351 | 2362 |
2352 | 2363 |
2353 uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) { | 2364 uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) { |
2354 ASSERT(index >= 0 && index < length()); | 2365 ASSERT(index >= 0 && index < length()); |
2355 return GetChars()[index]; | 2366 return GetChars()[index]; |
2356 } | 2367 } |
2357 | 2368 |
2358 | 2369 |
2359 const uint16_t* ExternalTwoByteString::ExternalTwoByteStringGetData( | 2370 const uint16_t* ExternalTwoByteString::ExternalTwoByteStringGetData( |
(...skipping 2309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4669 #undef WRITE_INT_FIELD | 4680 #undef WRITE_INT_FIELD |
4670 #undef READ_SHORT_FIELD | 4681 #undef READ_SHORT_FIELD |
4671 #undef WRITE_SHORT_FIELD | 4682 #undef WRITE_SHORT_FIELD |
4672 #undef READ_BYTE_FIELD | 4683 #undef READ_BYTE_FIELD |
4673 #undef WRITE_BYTE_FIELD | 4684 #undef WRITE_BYTE_FIELD |
4674 | 4685 |
4675 | 4686 |
4676 } } // namespace v8::internal | 4687 } } // namespace v8::internal |
4677 | 4688 |
4678 #endif // V8_OBJECTS_INL_H_ | 4689 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |