summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:17:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:17:04 +0200
commit5d6f8aad8aaa3cdc3c52848c8adbc271dbe8e5e2 (patch)
tree804dd90f38ca601428ed9154d68ee7d16bf7db6a
parent47c792f60af45e91ede19333faf111bb14d0cd2b (diff)
Use a set instead of pre-sorted array for keywords
The pre-sorted array approach depends on the character encoding.
-rw-r--r--cli/context.cxx65
-rw-r--r--cli/context.hxx5
2 files changed, 39 insertions, 31 deletions
diff --git a/cli/context.cxx b/cli/context.cxx
index 3f3261c..5ee27aa 100644
--- a/cli/context.cxx
+++ b/cli/context.cxx
@@ -9,34 +9,6 @@
using namespace std;
-context::
-context (ostream& os_, semantics::cli_unit& unit_, options_type const& ops)
- : data_ (new (shared) data),
- os (os_),
- unit (unit_),
- options (ops),
- inl (data_->inl_),
- opt_prefix (options.option_prefix ()),
- opt_sep (options.option_separator ()),
- reserved_name_map (options.reserved_name ())
-{
- if (!options.suppress_inline ())
- data_->inl_ = "inline ";
-}
-
-context::
-context (context& c)
- : data_ (c.data_),
- os (c.os),
- unit (c.unit),
- options (c.options),
- inl (c.inl),
- opt_prefix (c.opt_prefix),
- opt_sep (c.opt_sep),
- reserved_name_map (c.reserved_name_map)
-{
-}
-
namespace
{
char const* keywords[] =
@@ -119,6 +91,39 @@ namespace
};
}
+context::
+context (ostream& os_, semantics::cli_unit& unit_, options_type const& ops)
+ : data_ (new (shared) data),
+ os (os_),
+ unit (unit_),
+ options (ops),
+ inl (data_->inl_),
+ opt_prefix (options.option_prefix ()),
+ opt_sep (options.option_separator ()),
+ reserved_name_map (options.reserved_name ()),
+ keyword_set (data_->keyword_set_)
+{
+ if (!options.suppress_inline ())
+ data_->inl_ = "inline ";
+
+ for (size_t i (0); i < sizeof (keywords) / sizeof (char*); ++i)
+ data_->keyword_set_.insert (keywords[i]);
+}
+
+context::
+context (context& c)
+ : data_ (c.data_),
+ os (c.os),
+ unit (c.unit),
+ options (c.options),
+ inl (c.inl),
+ opt_prefix (c.opt_prefix),
+ opt_sep (c.opt_sep),
+ reserved_name_map (c.reserved_name_map),
+ keyword_set (c.keyword_set)
+{
+}
+
string context::
escape (string const& name) const
{
@@ -169,9 +174,7 @@ escape (string const& name) const
// Keywords
//
- size const ks (sizeof (keywords) / sizeof (char*));
-
- if (std::binary_search (keywords, keywords + ks, r))
+ if (keyword_set.find (r) != keyword_set.end ())
{
r += '_';
diff --git a/cli/context.hxx b/cli/context.hxx
index 37864af..1f2facb 100644
--- a/cli/context.hxx
+++ b/cli/context.hxx
@@ -6,6 +6,7 @@
#ifndef CLI_CONTEXT_HXX
#define CLI_CONTEXT_HXX
+#include <set>
#include <map>
#include <string>
#include <ostream>
@@ -42,10 +43,14 @@ public:
typedef std::map<string, string> reserved_name_map_type;
reserved_name_map_type const& reserved_name_map;
+ typedef std::set<string> keyword_set_type;
+ keyword_set_type const& keyword_set;
+
private:
struct data
{
string inl_;
+ keyword_set_type keyword_set_;
};
public: