Ignore:
Timestamp:
Oct 2, 2014, 3:22:19 PM (5 years ago)
Author:
nmedfort
Message:

Performance bug fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4194 r4203  
    3333}
    3434
    35 template<class T>
    36 inline static RE * simplify_vector(T & vec) {
    37     RE * re;
    38     if (vec->size() == 1) {
    39         re = vec->back();
    40         vec->pop_back();
    41     }
    42     else {
    43         re = vec.release();
    44     }
    45     return re;
    46 }
    47 
    4835RE * RE_Parser::parse_alt(const bool subexpression) {
    49     std::unique_ptr<Alt> alt(makeAlt());
     36    std::vector<RE *> alt;
    5037    for (;;) {
    51         alt->push_back(parse_seq());
     38        alt.push_back(parse_seq());
    5239        if (_cursor == _end || *_cursor != '|') {
    5340            break;
     
    5542        ++_cursor; // advance past the alternation character '|'
    5643    }
    57     if (alt->empty())
     44    if (alt.empty())
    5845    {
    5946        throw NoRegularExpressionFound();
     
    6855        throw ParseFailure("Cannot fully parse statement!");
    6956    }
    70     return simplify_vector(alt);
     57    return makeAlt(alt.begin(), alt.end());
    7158}
    7259
    7360inline RE * RE_Parser::parse_seq() {
    74     std::unique_ptr<Seq> seq(makeSeq());
     61    std::vector<RE *> seq;
    7562    for (;;) {
    7663        RE * re = parse_next_token();
     
    7865            break;
    7966        }
    80         seq->push_back(extend_item(re));
    81     }
    82     if (seq->empty())
     67        seq.push_back(extend_item(re));
     68    }
     69    if (seq.empty())
    8370    {
    8471        throw NoRegularExpressionFound();
    8572    }
    86     return simplify_vector(seq);
     73    return makeSeq(Seq::Type::Normal, seq.begin(), seq.end());
    8774}
    8875
     
    159146    ++_cursor;
    160147    throw_incomplete_expression_error_if_end_of_stream();
    161     Rep * rep = nullptr;
     148    RE * rep = nullptr;
    162149    unsigned lower_bound;
    163150    if (*_cursor == ',') {
Note: See TracChangeset for help on using the changeset viewer.