]> sourceware.org Git - systemtap.git/commitdiff
parser/scanner speedup
authorFrank Ch. Eigler <fche@elastic.org>
Thu, 11 Sep 2008 03:11:30 +0000 (23:11 -0400)
committerFrank Ch. Eigler <fche@elastic.org>
Thu, 11 Sep 2008 03:11:30 +0000 (23:11 -0400)
ChangeLog
parse.cxx
parse.h

index 1c5755359ad7e055f5c26dfd8be7ac4b4350e9d8..ae88d65363d90fcbaf01384c1a8e403c3d11ba6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-09-10  Frank Ch. Eigler  <fche@elastic.org>
+
+       * parse.cxx, parse.h: Rewrite scanner lookahead data structure
+       to a simple ~fixed vector.
+
 2008-09-10  Frank Ch. Eigler  <fche@elastic.org>
 
        PR6876: translator speedup for many $vars
index 00991022cbb752f44223eab681054a7be00222a4..1c1772f62518444de67a90772bc9a1a3a798ac5a 100644 (file)
--- a/parse.cxx
+++ b/parse.cxx
@@ -15,6 +15,7 @@
 #include "util.h"
 
 #include <iostream>
+
 #include <fstream>
 #include <cctype>
 #include <cstdlib>
@@ -24,6 +25,8 @@
 #include <sstream>
 #include <cstring>
 #include <cctype>
+#include <iterator>
+
 extern "C" {
 #include <fnmatch.h>
 }
@@ -576,20 +579,23 @@ parser::peek_kw (std::string const & kw)
 
 
 lexer::lexer (istream& i, const string& in, systemtap_session& s):
-  input (i), input_name (in), cursor_suspend_count(0),
+  input (i), input_name (in),
+  input_pointer (0), cursor_suspend_count(0),
   cursor_line (1), cursor_column (1), session(s)
-{ }
+{
+  char c;
+  while(input.get(c))
+    input_contents.push_back(c);
+}
 
 
 int
 lexer::input_peek (unsigned n)
 {
-  while (lookahead.size() <= n)
-    {
-      int c = input.get ();
-      lookahead.push_back (input ? c : -1);
-    }
-  return lookahead[n];
+  if (input_contents.size() > (input_pointer + n))
+    return (int)(unsigned char)input_contents[input_pointer+n];
+  else
+    return -1;
 }
 
 
@@ -597,7 +603,7 @@ int
 lexer::input_get ()
 {
   int c = input_peek (0);
-  lookahead.erase (lookahead.begin ());
+  input_pointer ++;
 
   if (c < 0) return c; // EOF
 
@@ -617,6 +623,7 @@ lexer::input_get ()
         cursor_column ++;
     }
 
+  // clog << "[" << (char)c << "]";
   return c;
 }
 
@@ -624,13 +631,9 @@ lexer::input_get ()
 void
 lexer::input_put (const string& chars)
 {
-  // clog << "[put:" << chars << "]";
-  for (int i=chars.size()-1; i>=0; i--)
-    {
-      int c = chars[i];
-      lookahead.insert (lookahead.begin(), c);
-      cursor_suspend_count ++;
-    }
+  // clog << "[put:" << chars << " @" << input_pointer << "]";
+  input_contents.insert (input_contents.begin() + input_pointer, chars.begin(), chars.end());
+  cursor_suspend_count += chars.size();
 }
 
 
diff --git a/parse.h b/parse.h
index 25c4293154714c4d5e5f8f6a06d109d3c5e1ad48..50b1507d215c5b4b335e535c68d4bbe957e1a2dd 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -79,7 +79,8 @@ private:
   int input_peek (unsigned n=0);
   std::istream& input;
   std::string input_name;
-  std::vector<int> lookahead;
+  std::vector<char> input_contents;
+  int input_pointer; // index into input_contents
   unsigned cursor_suspend_count;
   unsigned cursor_line;
   unsigned cursor_column;
This page took 0.040074 seconds and 5 git commands to generate.