]> granicus.if.org Git - taglib/commitdiff
A couple more optimizations for splitting vectors. One of them makes search
authorScott Wheeler <wheeler@kde.org>
Fri, 16 Jun 2006 22:38:20 +0000 (22:38 +0000)
committerScott Wheeler <wheeler@kde.org>
Fri, 16 Jun 2006 22:38:20 +0000 (22:38 +0000)
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

toolkit/tbytevector.cpp
toolkit/tbytevectorlist.cpp

index 241a08c55eea886085b7e0124eae36a80938ef24..46e015d5cbb838b155c94d5939f43fadec7795b5 100644 (file)
@@ -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)
index f2b2c128f61c85e094429b3dd0e86826f4723693..7661336928ff59c1c470be7117e042469e415a9d 100644 (file)
@@ -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();
   }