OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 cons_string->set_length(length); | 2005 cons_string->set_length(length); |
2006 cons_string->set_hash_field(String::kEmptyHashField); | 2006 cons_string->set_hash_field(String::kEmptyHashField); |
2007 cons_string->set_first(first, mode); | 2007 cons_string->set_first(first, mode); |
2008 cons_string->set_second(second, mode); | 2008 cons_string->set_second(second, mode); |
2009 return result; | 2009 return result; |
2010 } | 2010 } |
2011 | 2011 |
2012 | 2012 |
2013 Object* Heap::AllocateSubString(String* buffer, | 2013 Object* Heap::AllocateSubString(String* buffer, |
2014 int start, | 2014 int start, |
2015 int end) { | 2015 int end, |
| 2016 PretenureFlag pretenure) { |
2016 int length = end - start; | 2017 int length = end - start; |
2017 | 2018 |
2018 if (length == 1) { | 2019 if (length == 1) { |
2019 return Heap::LookupSingleCharacterStringFromCode( | 2020 return Heap::LookupSingleCharacterStringFromCode( |
2020 buffer->Get(start)); | 2021 buffer->Get(start)); |
2021 } else if (length == 2) { | 2022 } else if (length == 2) { |
2022 // Optimization for 2-byte strings often used as keys in a decompression | 2023 // Optimization for 2-byte strings often used as keys in a decompression |
2023 // dictionary. Check whether we already have the string in the symbol | 2024 // dictionary. Check whether we already have the string in the symbol |
2024 // table to prevent creation of many unneccesary strings. | 2025 // table to prevent creation of many unneccesary strings. |
2025 unsigned c1 = buffer->Get(start); | 2026 unsigned c1 = buffer->Get(start); |
2026 unsigned c2 = buffer->Get(start + 1); | 2027 unsigned c2 = buffer->Get(start + 1); |
2027 return MakeOrFindTwoCharacterString(c1, c2); | 2028 return MakeOrFindTwoCharacterString(c1, c2); |
2028 } | 2029 } |
2029 | 2030 |
2030 // Make an attempt to flatten the buffer to reduce access time. | 2031 // Make an attempt to flatten the buffer to reduce access time. |
2031 if (!buffer->IsFlat()) { | 2032 buffer->TryFlatten(); |
2032 buffer->TryFlatten(); | |
2033 } | |
2034 | 2033 |
2035 Object* result = buffer->IsAsciiRepresentation() | 2034 Object* result = buffer->IsAsciiRepresentation() |
2036 ? AllocateRawAsciiString(length) | 2035 ? AllocateRawAsciiString(length, pretenure ) |
2037 : AllocateRawTwoByteString(length); | 2036 : AllocateRawTwoByteString(length, pretenure); |
2038 if (result->IsFailure()) return result; | 2037 if (result->IsFailure()) return result; |
2039 String* string_result = String::cast(result); | 2038 String* string_result = String::cast(result); |
2040 | |
2041 // Copy the characters into the new object. | 2039 // Copy the characters into the new object. |
2042 if (buffer->IsAsciiRepresentation()) { | 2040 if (buffer->IsAsciiRepresentation()) { |
2043 ASSERT(string_result->IsAsciiRepresentation()); | 2041 ASSERT(string_result->IsAsciiRepresentation()); |
2044 char* dest = SeqAsciiString::cast(string_result)->GetChars(); | 2042 char* dest = SeqAsciiString::cast(string_result)->GetChars(); |
2045 String::WriteToFlat(buffer, dest, start, end); | 2043 String::WriteToFlat(buffer, dest, start, end); |
2046 } else { | 2044 } else { |
2047 ASSERT(string_result->IsTwoByteRepresentation()); | 2045 ASSERT(string_result->IsTwoByteRepresentation()); |
2048 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | 2046 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); |
2049 String::WriteToFlat(buffer, dest, start, end); | 2047 String::WriteToFlat(buffer, dest, start, end); |
2050 } | 2048 } |
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4240 void ExternalStringTable::TearDown() { | 4238 void ExternalStringTable::TearDown() { |
4241 new_space_strings_.Free(); | 4239 new_space_strings_.Free(); |
4242 old_space_strings_.Free(); | 4240 old_space_strings_.Free(); |
4243 } | 4241 } |
4244 | 4242 |
4245 | 4243 |
4246 List<Object*> ExternalStringTable::new_space_strings_; | 4244 List<Object*> ExternalStringTable::new_space_strings_; |
4247 List<Object*> ExternalStringTable::old_space_strings_; | 4245 List<Object*> ExternalStringTable::old_space_strings_; |
4248 | 4246 |
4249 } } // namespace v8::internal | 4247 } } // namespace v8::internal |
OLD | NEW |