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