From b87590ce9d01d4d09fc1fd1198aea1ff04225137 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Wed, 2 Dec 2015 09:38:20 +1100 Subject: [PATCH] castle: simplify find_next_top Tops are no longer sparse in CastleProto, so the linear scan for holes isn't necessary. --- src/nfa/castlecompile.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/nfa/castlecompile.cpp b/src/nfa/castlecompile.cpp index e7e40540..b18eb9ad 100644 --- a/src/nfa/castlecompile.cpp +++ b/src/nfa/castlecompile.cpp @@ -721,10 +721,8 @@ const CharReach &CastleProto::reach() const { static u32 find_next_top(const map &repeats) { - u32 top = 0; - for (; contains(repeats, top); top++) { - // pass - } + u32 top = verify_u32(repeats.size()); + assert(!contains(repeats, top)); return top; } @@ -734,7 +732,7 @@ u32 CastleProto::add(const PureRepeat &pr) { assert(pr.reports.size() == 1); u32 top = find_next_top(repeats); DEBUG_PRINTF("selected unused top %u\n", top); - repeats.insert(make_pair(top, pr)); + repeats.emplace(top, pr); return top; } @@ -783,7 +781,7 @@ bool mergeCastle(CastleProto &c1, const CastleProto &c2, const PureRepeat &pr = m.second; DEBUG_PRINTF("top %u\n", top); u32 new_top = find_next_top(c1.repeats); - c1.repeats.insert(make_pair(new_top, pr)); + c1.repeats.emplace(new_top, pr); top_map[top] = new_top; DEBUG_PRINTF("adding repeat: map %u->%u\n", top, new_top); } @@ -800,7 +798,7 @@ void remapCastleTops(CastleProto &proto, map &top_map) { const u32 top = m.first; const PureRepeat &pr = m.second; u32 new_top = find_next_top(out); - out.insert(make_pair(new_top, pr)); + out.emplace(new_top, pr); top_map[top] = new_top; }