]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Remove "dot" entries from leftfix lookarounds
authorJustin Viiret <justin.viiret@intel.com>
Wed, 6 Jan 2016 00:45:31 +0000 (11:45 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:23:06 +0000 (11:23 +1100)
Note that we have to be careful to leave the first lookaround entry in
place, if it's a dot. This should eventually be done with a program
instruction.

src/rose/rose_build_lookaround.cpp

index 02843feeb090d10373afb76a1f8d489dea315bd4..54c01e089252aa70cb98c8f7c7a46153df19d3fe 100644 (file)
@@ -582,6 +582,30 @@ bool getTransientPrefixReach(const NGHolder &g, u32 lag,
     return true;
 }
 
+static
+void normaliseLeftfix(map<s32, CharReach> &look) {
+    // We can erase entries where the reach is "all characters", except for the
+    // very first one -- this might be required to establish a minimum bound on
+    // the literal's match offset.
+
+    // TODO: It would be cleaner to use a literal program instruction to check
+    // the minimum bound explicitly.
+
+    if (look.empty()) {
+        return;
+    }
+
+    const auto earliest = begin(look)->first;
+
+    vector<s32> dead;
+    for (const auto &m : look) {
+        if (m.second.all() && m.first != earliest) {
+            dead.push_back(m.first);
+        }
+    }
+    erase_all(&look, dead);
+}
+
 bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v,
                            vector<LookEntry> &lookaround) {
     lookaround.clear();
@@ -606,6 +630,7 @@ bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v,
     }
 
     trimLiterals(build, v, look);
+    normaliseLeftfix(look);
 
     if (look.size() > MAX_LOOKAROUND_ENTRIES) {
         DEBUG_PRINTF("lookaround too big (%zu entries)\n", look.size());