diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-09-10 23:11:30 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-09-10 23:11:30 -0400 |
commit | eacb10cec9899c79ae1e122a7b6e50106928a295 (patch) | |
tree | ac74a690f79f85eae483404a0acaf6732c01ed25 | |
parent | 9c98fb062af789df50ab98284ff2c6da3e220343 (diff) | |
download | systemtap-steved-eacb10cec9899c79ae1e122a7b6e50106928a295.tar.gz systemtap-steved-eacb10cec9899c79ae1e122a7b6e50106928a295.tar.xz systemtap-steved-eacb10cec9899c79ae1e122a7b6e50106928a295.zip |
parser/scanner speedup
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | parse.cxx | 35 | ||||
-rw-r--r-- | parse.h | 3 |
3 files changed, 26 insertions, 17 deletions
@@ -1,5 +1,10 @@ 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 * session.h (systemtap_session.functions): vector->map. * coveragedb.cxx, elaborate.cxx, main.cxx, tapsets.cxx, translate.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(); } @@ -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; |