Mercurial > hg > Members > shinya > pyrect
changeset 76:dd6d2b9e48ad
improvement quick-filtering.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Nov 2010 04:47:34 +0900 |
parents | e06786b3c2dc |
children | c50511498bcf |
files | pyrect/translator/grep_translator.py |
diffstat | 1 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/pyrect/translator/grep_translator.py Mon Nov 08 03:45:14 2010 +0900 +++ b/pyrect/translator/grep_translator.py Mon Nov 08 04:47:34 2010 +0900 @@ -117,12 +117,14 @@ for i in range(l-1): skip[key[i]] = l-1-i - self.emit("UCHARP tmp;", 2) - self.emit("int i; buf += %d;" % (l-1)) - self.emiti("while ((tmp = buf) < end) {") - self.emiti( "if (%s) {" % - " && ".join(reversed(["*tmp-- == %d" % ord(c) for c in key]))) - self.emit( "goto next;") + self.emit("UCHARP tmp1, *tmp2;", 2) + self.emit("buf += %d;" % (l-1)) + self.emiti("while (buf < end) {") + self.emiti( "if (*buf == %d /*%c*/) {" % (ord(key[-1]), key[-1])) + self.emit( "tmp1 = buf, tmp2 = key+%d;" % (l-1)) + self.emiti( "while (*(--tmp1) == *(--tmp2)) {") + self.emit( "if (tmp2 == key) goto next;") + self.emitd( "}") self.emitd( "}") self.emiti( "switch(*buf) {") for k, v in skip.iteritems(): @@ -166,11 +168,13 @@ for i in range(l): skip[key[i]] = l-i - self.emit("UCHARP tmp, *end_ = end - %d;" % l, 2) - self.emiti("while ((tmp = buf) <= end_) {") - self.emiti( "if (%s) {" % - " && ".join(["*tmp++ == %d" % ord(c) for c in key])) - self.emit( "goto next;") + self.emit("UCHARP tmp1, *tmp2, *end_ = end - %d;" % (l-1), 2) + self.emiti("while (buf < end_) {") + self.emiti( "if (*buf == %d) {" % ord(key[0])) + self.emit( "tmp1 = buf, tmp2 = key;") + self.emiti( "while (*(++tmp1) == *(++tmp2)){") + self.emit( "if (tmp2 == key+%d) goto next;" % (l-1)) + self.emitd( "}") self.emitd( "}") self.emiti( "switch(buf[%d]) {" % l) for k, v in skip.iteritems():