| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 int read = static_cast<int>(fread(&chars[i], 1, file_size - i, file)); | 65 int read = static_cast<int>(fread(&chars[i], 1, file_size - i, file)); |
| 66 i += read; | 66 i += read; |
| 67 } | 67 } |
| 68 fclose(file); | 68 fclose(file); |
| 69 | 69 |
| 70 for (int i = file_size; i < size; i++) { | 70 for (int i = file_size; i < size; i++) { |
| 71 chars[i] = chars[i - file_size]; | 71 chars[i] = chars[i - file_size]; |
| 72 } | 72 } |
| 73 *end = &chars[size]; | 73 *end = &chars[size]; |
| 74 | 74 |
| 75 if (!convert_to_utf16) | 75 if (!convert_to_utf16) return chars; |
| 76 return chars; | |
| 77 | 76 |
| 78 // Length of new_chars is not strictly accurate, but should be enough. | 77 // Length of new_chars is not strictly accurate, but should be enough. |
| 79 uint16_t* new_chars = new uint16_t[size]; | 78 uint16_t* new_chars = new uint16_t[size]; |
| 80 { | 79 { |
| 81 Utf8ToUtf16CharacterStream stream(chars, size); | 80 Utf8ToUtf16CharacterStream stream(chars, size); |
| 82 uint16_t* cursor = new_chars; | 81 uint16_t* cursor = new_chars; |
| 83 uc32 c; | 82 uc32 c; |
| 84 // The 32-bit char type is probably only so that we can have -1 as a return | 83 // The 32-bit char type is probably only so that we can have -1 as a return |
| 85 // value. If the char is not -1, it should fit into 16 bits. | 84 // value. If the char is not -1, it should fit into 16 bits. |
| 86 while ((c = stream.Advance()) != -1) | 85 while ((c = stream.Advance()) != -1) { |
| 87 *cursor++ = c; | 86 *cursor++ = c; |
| 87 } |
| 88 *end = reinterpret_cast<byte*>(cursor); | 88 *end = reinterpret_cast<byte*>(cursor); |
| 89 } | 89 } |
| 90 delete[] chars; | 90 delete[] chars; |
| 91 return reinterpret_cast<byte*>(new_chars); | 91 return reinterpret_cast<byte*>(new_chars); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 enum Encoding { | 95 enum Encoding { |
| 96 LATIN1, | 96 LATIN1, |
| 97 UTF8, | 97 UTF8, |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (run_experimental) { | 488 if (run_experimental) { |
| 489 if (benchmark.empty()) benchmark = "Experimental"; | 489 if (benchmark.empty()) benchmark = "Experimental"; |
| 490 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), | 490 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 491 experimental_total); | 491 experimental_total); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 v8::V8::Dispose(); | 495 v8::V8::Dispose(); |
| 496 return 0; | 496 return 0; |
| 497 } | 497 } |
| OLD | NEW |