From: Scott Wheeler Date: Fri, 16 Jun 2006 22:38:20 +0000 (+0000) Subject: A couple more optimizations for splitting vectors. One of them makes search X-Git-Tag: v1.5~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e83f93b2c0c65e1cd26ab5f608c7ccb1ba72df5a;p=taglib A couple more optimizations for splitting vectors. One of them makes search faster in the simple case (no need for Boyer-Moore for a one-character search) and append a null vector rather than instantiating a new one when we find empty fields. This gets the reading time down to 6 seconds here for the reported bug, which still isn't great, but it's starting to get close to acceptable. I'll see if I can get it a little tighter... BUG:122183 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@552196 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/toolkit/tbytevector.cpp b/toolkit/tbytevector.cpp index 241a08c5..46e015d5 100644 --- a/toolkit/tbytevector.cpp +++ b/toolkit/tbytevector.cpp @@ -92,6 +92,18 @@ namespace TagLib { if(pattern.size() > v.size() || offset >= v.size() - 1) return -1; + // Let's go ahead and special case a pattern of size one since that's common + // and easy to make fast. + + if(pattern.size() == 1) { + char p = pattern[0]; + for(uint i = offset; i < v.size(); i++) { + if(v[i] == p && i % byteAlign == 0) + return i; + } + return 0; + } + uchar lastOccurrence[256]; for(uint i = 0; i < 256; ++i) diff --git a/toolkit/tbytevectorlist.cpp b/toolkit/tbytevectorlist.cpp index f2b2c128..76613369 100644 --- a/toolkit/tbytevectorlist.cpp +++ b/toolkit/tbytevectorlist.cpp @@ -48,7 +48,11 @@ ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &patt offset != -1 && (max == 0 || max > int(l.size()) + 1); offset = v.find(pattern, offset + pattern.size(), byteAlign)) { - l.append(v.mid(previousOffset, offset - previousOffset)); + if(offset - previousOffset > 1) + l.append(v.mid(previousOffset, offset - previousOffset)); + else + l.append(ByteVector::null); + previousOffset = offset + pattern.size(); }