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 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 | 1954 |
1955 // Optimization for 2-byte strings often used as keys in a decompression | 1955 // Optimization for 2-byte strings often used as keys in a decompression |
1956 // dictionary. Check whether we already have the string in the symbol | 1956 // dictionary. Check whether we already have the string in the symbol |
1957 // table to prevent creation of many unneccesary strings. | 1957 // table to prevent creation of many unneccesary strings. |
1958 if (length == 2) { | 1958 if (length == 2) { |
1959 unsigned c1 = first->Get(0); | 1959 unsigned c1 = first->Get(0); |
1960 unsigned c2 = second->Get(0); | 1960 unsigned c2 = second->Get(0); |
1961 return MakeOrFindTwoCharacterString(c1, c2); | 1961 return MakeOrFindTwoCharacterString(c1, c2); |
1962 } | 1962 } |
1963 | 1963 |
1964 bool is_ascii = first->IsAsciiRepresentation() | 1964 bool first_is_ascii = first->IsAsciiRepresentation(); |
1965 && second->IsAsciiRepresentation(); | 1965 bool second_is_ascii = second->IsAsciiRepresentation(); |
| 1966 bool is_ascii = first_is_ascii && second_is_ascii; |
1966 | 1967 |
1967 // Make sure that an out of memory exception is thrown if the length | 1968 // Make sure that an out of memory exception is thrown if the length |
1968 // of the new cons string is too large. | 1969 // of the new cons string is too large. |
1969 if (length > String::kMaxLength || length < 0) { | 1970 if (length > String::kMaxLength || length < 0) { |
1970 Top::context()->mark_out_of_memory(); | 1971 Top::context()->mark_out_of_memory(); |
1971 return Failure::OutOfMemoryException(); | 1972 return Failure::OutOfMemoryException(); |
1972 } | 1973 } |
1973 | 1974 |
1974 // If the resulting string is small make a flat string. | 1975 // If the resulting string is small make a flat string. |
1975 if (length < String::kMinNonFlatLength) { | 1976 if (length < String::kMinNonFlatLength) { |
(...skipping 14 matching lines...) Expand all Loading... |
1990 for (int i = 0; i < first_length; i++) *dest++ = src[i]; | 1991 for (int i = 0; i < first_length; i++) *dest++ = src[i]; |
1991 // Copy second part. | 1992 // Copy second part. |
1992 if (second->IsExternalString()) { | 1993 if (second->IsExternalString()) { |
1993 src = ExternalAsciiString::cast(second)->resource()->data(); | 1994 src = ExternalAsciiString::cast(second)->resource()->data(); |
1994 } else { | 1995 } else { |
1995 src = SeqAsciiString::cast(second)->GetChars(); | 1996 src = SeqAsciiString::cast(second)->GetChars(); |
1996 } | 1997 } |
1997 for (int i = 0; i < second_length; i++) *dest++ = src[i]; | 1998 for (int i = 0; i < second_length; i++) *dest++ = src[i]; |
1998 return result; | 1999 return result; |
1999 } else { | 2000 } else { |
| 2001 // For short external two-byte strings we check whether they can |
| 2002 // be represented using ascii. |
| 2003 if (!first_is_ascii) { |
| 2004 first_is_ascii = first->IsExternalTwoByteStringWithAsciiChars(); |
| 2005 } |
| 2006 if (first_is_ascii && !second_is_ascii) { |
| 2007 second_is_ascii = second->IsExternalTwoByteStringWithAsciiChars(); |
| 2008 } |
| 2009 if (first_is_ascii && second_is_ascii) { |
| 2010 Object* result = AllocateRawAsciiString(length); |
| 2011 if (result->IsFailure()) return result; |
| 2012 // Copy the characters into the new object. |
| 2013 char* dest = SeqAsciiString::cast(result)->GetChars(); |
| 2014 String::WriteToFlat(first, dest, 0, first_length); |
| 2015 String::WriteToFlat(second, dest + first_length, 0, second_length); |
| 2016 Counters::string_add_runtime_ext_to_ascii.Increment(); |
| 2017 return result; |
| 2018 } |
| 2019 |
2000 Object* result = AllocateRawTwoByteString(length); | 2020 Object* result = AllocateRawTwoByteString(length); |
2001 if (result->IsFailure()) return result; | 2021 if (result->IsFailure()) return result; |
2002 // Copy the characters into the new object. | 2022 // Copy the characters into the new object. |
2003 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); | 2023 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |
2004 String::WriteToFlat(first, dest, 0, first_length); | 2024 String::WriteToFlat(first, dest, 0, first_length); |
2005 String::WriteToFlat(second, dest + first_length, 0, second_length); | 2025 String::WriteToFlat(second, dest + first_length, 0, second_length); |
2006 return result; | 2026 return result; |
2007 } | 2027 } |
2008 } | 2028 } |
2009 | 2029 |
(...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4366 void ExternalStringTable::TearDown() { | 4386 void ExternalStringTable::TearDown() { |
4367 new_space_strings_.Free(); | 4387 new_space_strings_.Free(); |
4368 old_space_strings_.Free(); | 4388 old_space_strings_.Free(); |
4369 } | 4389 } |
4370 | 4390 |
4371 | 4391 |
4372 List<Object*> ExternalStringTable::new_space_strings_; | 4392 List<Object*> ExternalStringTable::new_space_strings_; |
4373 List<Object*> ExternalStringTable::old_space_strings_; | 4393 List<Object*> ExternalStringTable::old_space_strings_; |
4374 | 4394 |
4375 } } // namespace v8::internal | 4395 } } // namespace v8::internal |
OLD | NEW |