Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1268)

Unified Diff: test/cctest/test-api.cc

Issue 16147004: do aligned reads in ContainsOnlyOneByte (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments addressed Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a59dd16f7c47548a61a9ef88a565d8f0e452a751..10f8af1d4cf72ee2ab618448eb4e64fbd301cc8d 100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -17033,8 +17033,12 @@ TEST(ContainsOnlyOneByte) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
// Make a buffer long enough that it won't automatically be converted.
- const int length = 200;
- i::SmartArrayPointer<uint16_t> string_contents(new uint16_t[length]);
+ const int length = 512;
+ // Ensure word aligned assignment.
+ const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t);
+ i::SmartArrayPointer<uintptr_t>
+ aligned_contents(new uintptr_t[aligned_length]);
+ uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents);
// Set to contain only one byte.
for (int i = 0; i < length-1; i++) {
string_contents[i] = 0x41;
@@ -17042,10 +17046,10 @@ TEST(ContainsOnlyOneByte) {
string_contents[length-1] = 0;
// Simple case.
Handle<String> string;
- string = String::NewExternal(new TestResource(*string_contents));
+ string = String::NewExternal(new TestResource(string_contents));
CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
// Counter example.
- string = String::NewFromTwoByte(isolate, *string_contents);
+ string = String::NewFromTwoByte(isolate, string_contents);
CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
// Test left right and balanced cons strings.
Handle<String> base = String::NewFromUtf8(isolate, "a");
@@ -17059,7 +17063,7 @@ TEST(ContainsOnlyOneByte) {
balanced = String::Concat(balanced, right);
Handle<String> cons_strings[] = {left, balanced, right};
Handle<String> two_byte =
- String::NewExternal(new TestResource(*string_contents));
+ String::NewExternal(new TestResource(string_contents));
for (size_t i = 0; i < ARRAY_SIZE(cons_strings); i++) {
// Base assumptions.
string = cons_strings[i];
@@ -17070,6 +17074,24 @@ TEST(ContainsOnlyOneByte) {
string = String::Concat(cons_strings[i], two_byte);
CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
}
+ // Set bits in different positions
+ // for strings of different lengths and alignments.
+ for (int alignment = 0; alignment < 7; alignment++) {
+ for (int size = 2; alignment + size < length; size *= 2) {
+ int zero_offset = size + alignment;
+ string_contents[zero_offset] = 0;
+ for (int i = 0; i < size; i++) {
+ int shift = 8 + (i % 7);
+ string_contents[alignment + i] = 1 << shift;
+ string =
+ String::NewExternal(new TestResource(string_contents + alignment));
+ CHECK_EQ(size, string->Length());
+ CHECK(!string->ContainsOnlyOneByte());
+ string_contents[alignment + i] = 0x41;
+ }
+ string_contents[zero_offset] = 0x41;
+ }
+ }
}
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698