Changeset 4319 for icGREP


Ignore:
Timestamp:
Dec 4, 2014, 7:24:31 AM (5 years ago)
Author:
cameron
Message:

Optimize makeDiff, makeIntersect if both args are CCs

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4316 r4319  
    5454
    5555add_library(PabloADT pablo/pe_and.cpp pablo/pe_not.cpp pablo/pe_or.cpp  pablo/pabloAST.cpp  pablo/pe_sel.cpp  pablo/pe_xor.cpp pablo/codegenstate.cpp  pablo/symbol_generator.cpp pablo/analysis/useanalysis.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp)
    56 add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp)
     56add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp re/re_diff.cpp re/re_intersect.cpp)
    5757add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf_encoding.cpp utf8_encoder.cpp unicode_categories.h UCD/CaseFolding_txt.cpp)
    5858
  • icGREP/icgrep-devel/icgrep/re/re_cc.cpp

    r4287 r4319  
    195195}
    196196
    197 }
     197CC * subtractCC(const CC * cc1, const CC * cc2) {
     198    CC * diff = makeCC();
     199    for (const CharSetItem & i : cc1->mSparseCharSet) {
     200        diff->insert_range(i.lo_codepoint, i.hi_codepoint);
     201    }
     202    for (const CharSetItem & i : cc2->mSparseCharSet) {
     203        diff->remove_range(i.lo_codepoint, i.hi_codepoint);
     204    }
     205    return diff;
     206}
     207   
     208CC * intersectCC(const CC * a, const CC * b) {
     209    CC * isect = makeCC();
     210    auto ai = a->cbegin();
     211    const auto ai_end = a->cend();
     212    auto bi = b->cbegin();
     213    const auto bi_end = b->cend();
     214    while (ai != ai_end && bi != bi_end) {
     215        const CharSetItem & ra = *ai;
     216        const CharSetItem & rb = *bi;
     217        if (ra.hi_codepoint < rb.lo_codepoint) {
     218            ++ai;
     219            continue;
     220        }
     221        else if (rb.hi_codepoint < ra.lo_codepoint) {
     222            ++bi;
     223            continue;
     224        }
     225        isect->insert_range(std::max(ra.lo_codepoint, rb.lo_codepoint), std::min(ra.hi_codepoint, rb.hi_codepoint));
     226        if (ra.hi_codepoint < rb.hi_codepoint) ++ai;
     227        else ++bi;
     228    }
     229    return isect;
     230}
     231   
     232}
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4287 r4319  
    123123    friend CC * makeCC(const CodePointType lo, const CodePointType hi);
    124124    friend CC * makeCC(const CC * cc1, const CC * cc2);
     125    friend CC * subtractCC(const CC * cc1, const CC * cc2);
    125126    void* operator new (std::size_t size) noexcept {
    126127        return mAllocator.allocate(size);
     
    184185}
    185186
     187CC * subtractCC(const CC * cc1, const CC * cc2);
     188
     189CC * intersectCC(const CC * cc1, const CC * cc2);
    186190}
    187191
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4308 r4319  
    4040}
    4141
     42//#define USE_IF_FOR_NONFINAL 1
     43
    4244void RE_Compiler::compile(RE * re, PabloBlock & pb) {
    4345
     
    5557    mInitial = pb.createVar(pb.createAssign(initial, pb.createOr(u8pfx, u8single)));
    5658    #ifdef USE_IF_FOR_NONFINAL
    57     mNonFinal = pb.createVar(pb.createAssign(gs_nonfinal, pb.createZeroes()));
     59    mNonFinal = pb.createVar(pb.createAssign(nonfinal, pb.createZeroes()));
    5860    #endif
    5961    PabloAST * u8scope32 = pb.createAdvance(u8pfx3, 1);
     
    6264    #ifdef USE_IF_FOR_NONFINAL
    6365    PabloBlock it(pb);
    64     it.createAssign(gs_nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
     66    it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
    6567    pb.createIf(u8pfx, std::move(it));
    6668    #else
  • icGREP/icgrep-devel/icgrep/re/re_diff.h

    r4272 r4319  
    33
    44#include <re/re_re.h>
     5#include <re/re_cc.h>
    56
    67namespace re {
     
    2728    }
    2829protected:
    29     friend Diff * makeDiff(RE*, RE*);
     30    friend RE * makeDiff(RE*, RE*);
    3031    void* operator new (std::size_t size) noexcept {
    3132        return mAllocator.allocate(size);
     
    4445};
    4546
    46 inline Diff * makeDiff(RE * lh, RE * rh) {
    47     return new Diff(lh, rh);
    48 }
    49 
     47RE * makeDiff(RE * lh, RE * rh);
    5048}
    5149
  • icGREP/icgrep-devel/icgrep/re/re_intersect.h

    r4298 r4319  
    2727    }
    2828protected:
    29     friend Intersect * makeIntersect(RE*, RE*);
     29    friend RE * makeIntersect(RE*, RE*);
    3030    void* operator new (std::size_t size) noexcept {
    3131        return mAllocator.allocate(size);
     
    4444};
    4545
    46 inline Intersect * makeIntersect(RE * lh, RE * rh) {
    47     return new Intersect(lh, rh);
    48 }
     46RE * makeIntersect(RE * lh, RE * rh);
    4947
    5048}
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4316 r4319  
    805805    if (count < mindigits) throw ParseFailure("Hexadecimal sequence has too few digits");
    806806    if (value > CC::UNICODE_MAX) throw ParseFailure("Hexadecimal value too large");
     807    std::cerr << value << " parsed.\n";
    807808    return value;
    808809}
Note: See TracChangeset for help on using the changeset viewer.