mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: [W]String::Find(String) optimized
git-svn-id: svn://ultimatepp.org/upp/trunk@6974 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
278c2b9cf0
commit
cfe40c31a1
1 changed files with 39 additions and 8 deletions
|
|
@ -83,7 +83,7 @@ int AString<B>::ReverseFind(int len, const tchar *s, int from) const
|
|||
const tchar *p = ptr + from - len + 1;
|
||||
len *= sizeof(tchar);
|
||||
while(p >= ptr) {
|
||||
if(memcmp(s, p, len) == 0)
|
||||
if(*s == *p && memcmp(s, p, len) == 0)
|
||||
return (int)(p - ptr);
|
||||
p--;
|
||||
}
|
||||
|
|
@ -125,18 +125,49 @@ template <class B>
|
|||
int AString<B>::Find(int len, const tchar *s, int from) const
|
||||
{
|
||||
ASSERT(from >= 0 && from <= GetLength());
|
||||
const tchar *ptr = B::Begin();
|
||||
const tchar *p = ptr + from;
|
||||
int l = GetLength() - len - from;
|
||||
if(l < 0)
|
||||
return -1;
|
||||
if(len == 0)
|
||||
return from;
|
||||
const tchar *ptr = B::Begin();
|
||||
const tchar *p = ptr + from;
|
||||
const tchar *e = p + l;
|
||||
len *= sizeof(tchar);
|
||||
while(p <= e) {
|
||||
if(memcmp(s, p, len) == 0)
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
if(len > 4) {
|
||||
len -= 4;
|
||||
while(p <= e) {
|
||||
if(s[0] == p[0] && s[1] == p[1] && s[2] == p[2] && s[3] == p[3] && memcmp(s + 4, p + 4, len * sizeof(tchar)) == 0)
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(len == 4)
|
||||
while(p <= e) {
|
||||
if(s[0] == p[0] && s[1] == p[1] && s[2] == p[2] && s[3] == p[3])
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
}
|
||||
else
|
||||
if(len == 3)
|
||||
while(p <= e) {
|
||||
if(s[0] == p[0] && s[1] == p[1] && s[2] == p[2])
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
}
|
||||
else
|
||||
if(len == 2)
|
||||
while(p <= e) {
|
||||
if(s[0] == p[0] && s[1] == p[1])
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
}
|
||||
else
|
||||
while(p <= e) {
|
||||
if(*s == *p)
|
||||
return (int)(p - ptr);
|
||||
p++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue