From 66c7d4c1a4147bc05abd1e69f41ec9d59685c433 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 9 Jul 2009 12:43:00 -0700 Subject: Optimize string usage in the lexer This speeds up the parsing stage >2x, mostly by minimizing string construction and comparison where char comparison will do. --- parse.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'parse.h') diff --git a/parse.h b/parse.h index 59046bf3..4cc4f7b2 100644 --- a/parse.h +++ b/parse.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -78,19 +79,19 @@ public: void set_current_file (stapfile* f); private: - int input_get (); - void input_put (int); + inline int input_get (); + inline int input_peek (unsigned n=0); void input_put (const std::string&); - int input_peek (unsigned n=0); - std::istream& input; std::string input_name; std::string input_contents; - int input_pointer; // index into input_contents + const char *input_pointer; // index into input_contents + const char *input_end; unsigned cursor_suspend_count; unsigned cursor_line; unsigned cursor_column; systemtap_session& session; stapfile* current_file; + static std::set keywords; }; struct probe; -- cgit From 2203b03262e340b25fc26996cc2786c1c02041e3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 9 Jul 2009 12:46:57 -0700 Subject: Remove the filename copy from token->location The location already has a pointer to a stapfile with the filename, so there's no need to keep an extra copy. --- parse.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'parse.h') diff --git a/parse.h b/parse.h index 4cc4f7b2..cae49b65 100644 --- a/parse.h +++ b/parse.h @@ -23,10 +23,9 @@ struct stapfile; struct source_loc { - std::string file; + stapfile* file; unsigned line; unsigned column; - stapfile* stap_file; }; std::ostream& operator << (std::ostream& o, const source_loc& loc); @@ -75,7 +74,6 @@ class lexer public: token* scan (bool wildcard=false); lexer (std::istream&, const std::string&, systemtap_session&); - std::string get_input_contents (); void set_current_file (stapfile* f); private: -- cgit