Changeset 1887 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Aug 20, 2002, 10:23:31 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r1852 r1887 488 488 int UString::find(const UString &f, int pos) const 489 489 { 490 if (size() < f.size()) 490 int sz = size(); 491 int fsz = f.size(); 492 if (sz < fsz) 491 493 return -1; 494 if (fsz == 0) 495 return 0; 492 496 if (pos < 0) 493 497 pos = 0; 494 const UChar *end = data() + s ize() - f.size();495 long fsize = f.size() * sizeof(UChar);496 const void*fdata = f.data();498 const UChar *end = data() + sz - fsz; 499 long fsizeminusone = (fsz - 1) * sizeof(UChar); 500 const UChar *fdata = f.data(); 497 501 for (const UChar *c = data() + pos; c <= end; c++) 498 if ( !memcmp(c, fdata, fsize))502 if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone)) 499 503 return (c-data()); 500 504 … … 516 520 int UString::rfind(const UString &f, int pos) const 517 521 { 518 if (size() < f.size()) 522 int sz = size(); 523 int fsz = f.size(); 524 if (sz < fsz) 519 525 return -1; 520 if (pos + f.size() >= size()) 521 pos = size() - f.size(); 522 long fsize = f.size() * sizeof(UChar); 523 const void *fdata = f.data(); 526 if (fsz == 0) 527 return 0; 528 if (pos < 0) 529 pos = 0; 530 long fsizeminusone = (fsz - 1) * sizeof(UChar); 531 const UChar *fdata = f.data(); 524 532 for (const UChar *c = data() + pos; c >= data(); c--) { 525 if ( !memcmp(c, fdata, fsize))533 if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone)) 526 534 return (c-data()); 527 535 } … … 603 611 } 604 612 605 if (s1.size() != (int)strlen(s2))606 return false;607 608 613 const UChar *u = s1.data(); 609 while (*s2) { 614 const UChar *uend = u + s1.size(); 615 while (u != uend && *s2) { 610 616 if (u->uc != (unsigned char)*s2) 611 617 return false; … … 614 620 } 615 621 616 return true;622 return u == uend && *s2 == 0; 617 623 } 618 624
Note:
See TracChangeset
for help on using the changeset viewer.