Skip to content

Commit

Permalink
reduce to array access
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentarctagon committed Sep 17, 2024
1 parent 6dfdca1 commit 43fc30c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/serialization/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tokenizer::tokenizer(std::istream& in) :
token_(),
in_(in)
{
for (int c = 0; c < START_EXTENDED_ASCII; ++c)
for (int c = 0; c < std::numeric_limits<unsigned char>::max(); ++c)
{
token_category t = TOK_NONE;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_') {
Expand Down
14 changes: 5 additions & 9 deletions src/serialization/tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "buffered_istream.hpp"

#include <limits>
#include <istream>
#include <string>

Expand Down Expand Up @@ -151,24 +152,19 @@ class tokenizer
TOK_ALPHA = 3
};

token_category char_type(unsigned c) const
{
return c < START_EXTENDED_ASCII ? char_types_[c] : TOK_NONE;
}

bool is_space(int c) const
{
return char_type(c) == TOK_SPACE;
return char_types_[c] == TOK_SPACE;
}

bool is_num(int c) const
{
return char_type(c) == TOK_NUMERIC;
return char_types_[c] == TOK_NUMERIC;
}

bool is_alnum(int c) const
{
return char_type(c) > TOK_SPACE;
return char_types_[c] > TOK_SPACE;
}

void skip_comment();
Expand All @@ -186,5 +182,5 @@ class tokenizer
token previous_token_;
#endif
buffered_istream in_;
token_category char_types_[START_EXTENDED_ASCII];
token_category char_types_[std::numeric_limits<unsigned char>::max()];
};

0 comments on commit 43fc30c

Please sign in to comment.