Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2125 | 2125 |
| 2126 // Convert all characters to upper case, assuming that they will fit | 2126 // Convert all characters to upper case, assuming that they will fit |
| 2127 // in the buffer | 2127 // in the buffer |
| 2128 Access<StringInputBuffer> buffer(&string_input_buffer); | 2128 Access<StringInputBuffer> buffer(&string_input_buffer); |
| 2129 buffer->Reset(s); | 2129 buffer->Reset(s); |
| 2130 unibrow::uchar chars[unibrow::kMaxCaseConvertedSize]; | 2130 unibrow::uchar chars[unibrow::kMaxCaseConvertedSize]; |
| 2131 int i = 0; | 2131 int i = 0; |
| 2132 // We can assume that the string is not empty | 2132 // We can assume that the string is not empty |
| 2133 uc32 current = buffer->GetNext(); | 2133 uc32 current = buffer->GetNext(); |
| 2134 while (i < length) { | 2134 while (i < length) { |
| 2135 uc32 next = buffer->has_more() ? buffer->GetNext() : 0; | 2135 bool has_next = buffer->has_more(); |
| 2136 uc32 next = has_next ? buffer->GetNext() : 0; | |
| 2136 int char_length = mapping->get(current, next, chars); | 2137 int char_length = mapping->get(current, next, chars); |
| 2137 if (char_length == 0) { | 2138 if (char_length == 0) { |
| 2138 // The case conversion of this character is the character itself. | 2139 // The case conversion of this character is the character itself. |
| 2139 result->Set(i, current); | 2140 result->Set(i, current); |
| 2140 i++; | 2141 i++; |
| 2141 } else if (char_length == 1) { | 2142 } else if (char_length == 1) { |
| 2142 // Common case: converting the letter resulted in one character. | 2143 // Common case: converting the letter resulted in one character. |
| 2143 ASSERT(static_cast<uc32>(chars[0]) != current); | 2144 ASSERT(static_cast<uc32>(chars[0]) != current); |
| 2144 result->Set(i, chars[0]); | 2145 result->Set(i, chars[0]); |
| 2145 has_changed_character = true; | 2146 has_changed_character = true; |
| 2146 i++; | 2147 i++; |
| 2147 } else if (length == raw_string_length) { | 2148 } else if (length == raw_string_length) { |
| 2148 // We've assumed that the result would be as long as the | 2149 // We've assumed that the result would be as long as the |
| 2149 // input but here is a character that converts to several | 2150 // input but here is a character that converts to several |
| 2150 // characters. No matter, we calculate the exact length | 2151 // characters. No matter, we calculate the exact length |
| 2151 // of the result and try the whole thing again. | 2152 // of the result and try the whole thing again. |
| 2152 // | 2153 // |
| 2153 // Note that this leaves room for optimization. We could just | 2154 // Note that this leaves room for optimization. We could just |
| 2154 // memcpy what we already have to the result string. Also, | 2155 // memcpy what we already have to the result string. Also, |
| 2155 // the result string is the last object allocated we could | 2156 // the result string is the last object allocated we could |
| 2156 // "realloc" it and probably, in the vast majority of cases, | 2157 // "realloc" it and probably, in the vast majority of cases, |
| 2157 // extend the existing string to be able to hold the full | 2158 // extend the existing string to be able to hold the full |
| 2158 // result. | 2159 // result. |
| 2159 int current_length = i + char_length + mapping->get(next, 0, chars); | 2160 int next_length = 0; |
| 2161 if (has_next) { | |
| 2162 next_length = mapping->get(next, 0, chars); | |
|
Erik Corry
2008/10/14 09:01:53
Missing comment here to explain why 0 is OK.
| |
| 2163 if (next_length == 0) next_length = 1; | |
| 2164 } | |
| 2165 int current_length = i + char_length + next_length; | |
| 2160 while (buffer->has_more()) { | 2166 while (buffer->has_more()) { |
| 2161 current = buffer->GetNext(); | 2167 current = buffer->GetNext(); |
| 2162 int char_length = mapping->get(current, 0, chars); | 2168 int char_length = mapping->get(current, 0, chars); |
| 2163 if (char_length == 0) char_length = 1; | 2169 if (char_length == 0) char_length = 1; |
| 2164 current += char_length; | 2170 current_length += char_length; |
| 2165 } | 2171 } |
| 2166 length = current_length; | 2172 length = current_length; |
| 2167 goto try_convert; | 2173 goto try_convert; |
| 2168 } else { | 2174 } else { |
| 2169 for (int j = 0; j < char_length; j++) { | 2175 for (int j = 0; j < char_length; j++) { |
| 2170 result->Set(i, chars[j]); | 2176 result->Set(i, chars[j]); |
| 2171 i++; | 2177 i++; |
| 2172 } | 2178 } |
| 2173 has_changed_character = true; | 2179 has_changed_character = true; |
| 2174 } | 2180 } |
| (...skipping 3047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5222 | 5228 |
| 5223 void Runtime::PerformGC(Object* result) { | 5229 void Runtime::PerformGC(Object* result) { |
| 5224 Failure* failure = Failure::cast(result); | 5230 Failure* failure = Failure::cast(result); |
| 5225 // Try to do a garbage collection; ignore it if it fails. The C | 5231 // Try to do a garbage collection; ignore it if it fails. The C |
| 5226 // entry stub will throw an out-of-memory exception in that case. | 5232 // entry stub will throw an out-of-memory exception in that case. |
| 5227 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); | 5233 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); |
| 5228 } | 5234 } |
| 5229 | 5235 |
| 5230 | 5236 |
| 5231 } } // namespace v8::internal | 5237 } } // namespace v8::internal |
| OLD | NEW |