[Scummvm-cvs-logs] SF.net SVN: scummvm:[34367] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Fri Sep 5 22:29:03 CEST 2008
Revision: 34367
http://scummvm.svn.sourceforge.net/scummvm/?rev=34367&view=rev
Author: fingolfin
Date: 2008-09-05 20:29:03 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Optimized matchString for the common case where there is a trailing * (if that is the case, abort immediately instead of scanning the rest of the string)
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
scummvm/trunk/test/common/str.h
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2008-09-05 20:26:36 UTC (rev 34366)
+++ scummvm/trunk/common/str.cpp 2008-09-05 20:29:03 UTC (rev 34367)
@@ -605,13 +605,18 @@
for (;;) {
switch (*pat) {
case '*':
+ // Record pattern / string possition for backtracking
p = ++pat;
q = str;
+ // If pattern ended with * -> match
+ if (!*pat)
+ return true;
break;
default:
if (*pat != *str) {
if (p) {
+ // No match, oops -> try to backtrack
pat = p;
str = ++q;
if (!*str)
Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h 2008-09-05 20:26:36 UTC (rev 34366)
+++ scummvm/trunk/test/common/str.h 2008-09-05 20:29:03 UTC (rev 34367)
@@ -191,6 +191,14 @@
}
void test_matchString(void) {
+ TS_ASSERT( Common::matchString("", "*"));
+ TS_ASSERT( Common::matchString("a", "*"));
+ TS_ASSERT( Common::matchString("monkey.s01", "*"));
+
+ TS_ASSERT(!Common::matchString("", "?"));
+ TS_ASSERT( Common::matchString("a", "?"));
+ TS_ASSERT(!Common::matchString("monkey.s01", "?"));
+
TS_ASSERT( Common::matchString("monkey.s01", "monkey.s??"));
TS_ASSERT( Common::matchString("monkey.s99", "monkey.s??"));
TS_ASSERT(!Common::matchString("monkey.s101", "monkey.s??"));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list