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

Side by Side Diff: test/cctest/test-strings.cc

Issue 11428106: Add StringBufferStream (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Right traversal optimization Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« src/objects-inl.h ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 192
193 193
194 static Handle<String> ConstructBalanced( 194 static Handle<String> ConstructBalanced(
195 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { 195 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) {
196 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH); 196 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH);
197 } 197 }
198 198
199 199
200 static StringInputBuffer buffer; 200 static StringInputBuffer buffer;
201 201 static ConsStringIteratorOp consStringIteratorOp;
202 202
203 static void Traverse(Handle<String> s1, Handle<String> s2) { 203 static void Traverse(Handle<String> s1, Handle<String> s2) {
204 int i = 0; 204 int i = 0;
205 buffer.Reset(*s1); 205 buffer.Reset(*s1);
206 StringBufferStream bufferStream;
207 bufferStream.Reset(*s1, 0, &consStringIteratorOp);
206 StringInputBuffer buffer2(*s2); 208 StringInputBuffer buffer2(*s2);
207 while (buffer.has_more()) { 209 while (buffer.has_more()) {
208 CHECK(buffer2.has_more()); 210 CHECK(buffer2.has_more());
211 CHECK(bufferStream.has_more());
209 uint16_t c = buffer.GetNext(); 212 uint16_t c = buffer.GetNext();
210 CHECK_EQ(c, buffer2.GetNext()); 213 CHECK_EQ(c, buffer2.GetNext());
214 CHECK_EQ(c, bufferStream.GetNext());
211 i++; 215 i++;
212 } 216 }
217 CHECK(!bufferStream.has_more());
213 CHECK_EQ(s1->length(), i); 218 CHECK_EQ(s1->length(), i);
214 CHECK_EQ(s2->length(), i); 219 CHECK_EQ(s2->length(), i);
215 } 220 }
216 221
217 222
218 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { 223 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) {
219 int i = 0; 224 int i = 0;
220 buffer.Reset(*s1); 225 buffer.Reset(*s1);
221 StringInputBuffer buffer2(*s2); 226 StringInputBuffer buffer2(*s2);
227 StringBufferStream bufferStream;
228 bufferStream.Reset(*s1, 0, &consStringIteratorOp);
222 while (buffer.has_more() && i < chars) { 229 while (buffer.has_more() && i < chars) {
223 CHECK(buffer2.has_more()); 230 CHECK(buffer2.has_more());
231 CHECK(bufferStream.has_more());
224 uint16_t c = buffer.GetNext(); 232 uint16_t c = buffer.GetNext();
225 CHECK_EQ(c, buffer2.GetNext()); 233 CHECK_EQ(c, buffer2.GetNext());
234 CHECK_EQ(c, bufferStream.GetNext());
226 i++; 235 i++;
227 } 236 }
228 s1->Get(s1->length() - 1); 237 s1->Get(s1->length() - 1);
229 s2->Get(s2->length() - 1); 238 s2->Get(s2->length() - 1);
230 } 239 }
231 240
232 241
233 TEST(Traverse) { 242 TEST(Traverse) {
234 printf("TestTraverse\n"); 243 printf("TestTraverse\n");
235 InitializeVM(); 244 InitializeVM();
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 717
709 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); 718 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
710 CHECK(expected->Equals(result)); 719 CHECK(expected->Equals(result));
711 } 720 }
712 721
713 722
714 TEST(IsAscii) { 723 TEST(IsAscii) {
715 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); 724 CHECK(String::IsAscii(static_cast<char*>(NULL), 0));
716 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); 725 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0));
717 } 726 }
OLDNEW
« src/objects-inl.h ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698