| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 18933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18944 i::SmartArrayPointer<uintptr_t> | 18944 i::SmartArrayPointer<uintptr_t> |
| 18945 aligned_contents(new uintptr_t[aligned_length]); | 18945 aligned_contents(new uintptr_t[aligned_length]); |
| 18946 uint16_t* string_contents = | 18946 uint16_t* string_contents = |
| 18947 reinterpret_cast<uint16_t*>(aligned_contents.get()); | 18947 reinterpret_cast<uint16_t*>(aligned_contents.get()); |
| 18948 // Set to contain only one byte. | 18948 // Set to contain only one byte. |
| 18949 for (int i = 0; i < length-1; i++) { | 18949 for (int i = 0; i < length-1; i++) { |
| 18950 string_contents[i] = 0x41; | 18950 string_contents[i] = 0x41; |
| 18951 } | 18951 } |
| 18952 string_contents[length-1] = 0; | 18952 string_contents[length-1] = 0; |
| 18953 // Simple case. | 18953 // Simple case. |
| 18954 Handle<String> string; | 18954 Handle<String> string = |
| 18955 string = String::NewExternal(isolate, new TestResource(string_contents)); | 18955 String::NewExternal(isolate, |
| 18956 new TestResource(string_contents, NULL, false)); |
| 18956 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18957 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18957 // Counter example. | 18958 // Counter example. |
| 18958 string = String::NewFromTwoByte(isolate, string_contents); | 18959 string = String::NewFromTwoByte(isolate, string_contents); |
| 18959 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18960 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18960 // Test left right and balanced cons strings. | 18961 // Test left right and balanced cons strings. |
| 18961 Handle<String> base = String::NewFromUtf8(isolate, "a"); | 18962 Handle<String> base = String::NewFromUtf8(isolate, "a"); |
| 18962 Handle<String> left = base; | 18963 Handle<String> left = base; |
| 18963 Handle<String> right = base; | 18964 Handle<String> right = base; |
| 18964 for (int i = 0; i < 1000; i++) { | 18965 for (int i = 0; i < 1000; i++) { |
| 18965 left = String::Concat(base, left); | 18966 left = String::Concat(base, left); |
| 18966 right = String::Concat(right, base); | 18967 right = String::Concat(right, base); |
| 18967 } | 18968 } |
| 18968 Handle<String> balanced = String::Concat(left, base); | 18969 Handle<String> balanced = String::Concat(left, base); |
| 18969 balanced = String::Concat(balanced, right); | 18970 balanced = String::Concat(balanced, right); |
| 18970 Handle<String> cons_strings[] = {left, balanced, right}; | 18971 Handle<String> cons_strings[] = {left, balanced, right}; |
| 18971 Handle<String> two_byte = | 18972 Handle<String> two_byte = |
| 18972 String::NewExternal(isolate, new TestResource(string_contents)); | 18973 String::NewExternal(isolate, |
| 18974 new TestResource(string_contents, NULL, false)); |
| 18975 USE(two_byte); USE(cons_strings); |
| 18973 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { | 18976 for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) { |
| 18974 // Base assumptions. | 18977 // Base assumptions. |
| 18975 string = cons_strings[i]; | 18978 string = cons_strings[i]; |
| 18976 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18979 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18977 // Test left and right concatentation. | 18980 // Test left and right concatentation. |
| 18978 string = String::Concat(two_byte, cons_strings[i]); | 18981 string = String::Concat(two_byte, cons_strings[i]); |
| 18979 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18982 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18980 string = String::Concat(cons_strings[i], two_byte); | 18983 string = String::Concat(cons_strings[i], two_byte); |
| 18981 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18984 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18982 } | 18985 } |
| 18983 // Set bits in different positions | 18986 // Set bits in different positions |
| 18984 // for strings of different lengths and alignments. | 18987 // for strings of different lengths and alignments. |
| 18985 for (int alignment = 0; alignment < 7; alignment++) { | 18988 for (int alignment = 0; alignment < 7; alignment++) { |
| 18986 for (int size = 2; alignment + size < length; size *= 2) { | 18989 for (int size = 2; alignment + size < length; size *= 2) { |
| 18987 int zero_offset = size + alignment; | 18990 int zero_offset = size + alignment; |
| 18988 string_contents[zero_offset] = 0; | 18991 string_contents[zero_offset] = 0; |
| 18989 for (int i = 0; i < size; i++) { | 18992 for (int i = 0; i < size; i++) { |
| 18990 int shift = 8 + (i % 7); | 18993 int shift = 8 + (i % 7); |
| 18991 string_contents[alignment + i] = 1 << shift; | 18994 string_contents[alignment + i] = 1 << shift; |
| 18992 string = String::NewExternal( | 18995 string = String::NewExternal( |
| 18993 isolate, new TestResource(string_contents + alignment)); | 18996 isolate, |
| 18997 new TestResource(string_contents + alignment, NULL, false)); |
| 18994 CHECK_EQ(size, string->Length()); | 18998 CHECK_EQ(size, string->Length()); |
| 18995 CHECK(!string->ContainsOnlyOneByte()); | 18999 CHECK(!string->ContainsOnlyOneByte()); |
| 18996 string_contents[alignment + i] = 0x41; | 19000 string_contents[alignment + i] = 0x41; |
| 18997 } | 19001 } |
| 18998 string_contents[zero_offset] = 0x41; | 19002 string_contents[zero_offset] = 0x41; |
| 18999 } | 19003 } |
| 19000 } | 19004 } |
| 19001 } | 19005 } |
| 19002 | 19006 |
| 19003 | 19007 |
| (...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21966 | 21970 |
| 21967 | 21971 |
| 21968 TEST(TestFunctionCallOptimization) { | 21972 TEST(TestFunctionCallOptimization) { |
| 21969 i::FLAG_allow_natives_syntax = true; | 21973 i::FLAG_allow_natives_syntax = true; |
| 21970 ApiCallOptimizationChecker checker; | 21974 ApiCallOptimizationChecker checker; |
| 21971 checker.Run(true, true); | 21975 checker.Run(true, true); |
| 21972 checker.Run(false, true); | 21976 checker.Run(false, true); |
| 21973 checker.Run(true, false); | 21977 checker.Run(true, false); |
| 21974 checker.Run(false, false); | 21978 checker.Run(false, false); |
| 21975 } | 21979 } |
| OLD | NEW |