From 44c6aeefea7d8fbed7ac23a14f82c55c637c0acb Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 18 Mar 2015 11:08:44 +0000 Subject: [PATCH] Abstracted common used constant in a class variable. --- re2c/go.h | 1 + re2c/go_construct.cc | 6 ++++-- re2c/go_emit.cc | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/re2c/go.h b/re2c/go.h index b9e183e6..a53e4103 100644 --- a/re2c/go.h +++ b/re2c/go.h @@ -106,6 +106,7 @@ struct Bitmap struct CpgotoTable { + static const uint TABLE_SIZE; uint * table; CpgotoTable (const Span * span, uint nSpans); void emit (OutputFile & o, uint ind); diff --git a/re2c/go_construct.cc b/re2c/go_construct.cc index 99ec7776..524aca37 100644 --- a/re2c/go_construct.cc +++ b/re2c/go_construct.cc @@ -137,14 +137,16 @@ Bitmap::Bitmap (const Span * span, uint nSpans, const Span * hspan, uint hSpans, delete bspan; } +const uint CpgotoTable::TABLE_SIZE = 0x100; + CpgotoTable::CpgotoTable (const Span * span, uint nSpans) - : table (new uint [0x100]) + : table (new uint [TABLE_SIZE]) { uint c = 0; for (uint i = 0; i < nSpans; ++i) { vUsedLabels.insert(span[i].to->label); - for(; c < span[i].ub && c < 0x100; ++c) + for(; c < span[i].ub && c < TABLE_SIZE; ++c) { table[c] = span[i].to->label; } diff --git a/re2c/go_emit.cc b/re2c/go_emit.cc index 2dc26032..91118437 100644 --- a/re2c/go_emit.cc +++ b/re2c/go_emit.cc @@ -188,10 +188,10 @@ void CpgotoTable::emit (OutputFile & o, uint ind) { o << indent (ind) << "static void *" << mapCodeName["yytarget"] << "[256] = {\n"; o << indent (++ind); - for (uint i = 0; i <= 0xFF; ++i) + for (uint i = 0; i < TABLE_SIZE; ++i) { o << "&&" << labelPrefix << table[i]; - if (i == 0xFF) + if (i == TABLE_SIZE - 1) { o << "\n"; } -- 2.40.0