[Scummvm-cvs-logs] SF.net SVN: scummvm:[40323] scummvm/trunk/engines/sci/engine/stringfrag.cpp
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue May 5 14:20:28 CEST 2009
Revision: 40323
http://scummvm.svn.sourceforge.net/scummvm/?rev=40323&view=rev
Author: fingolfin
Date: 2009-05-05 12:20:28 +0000 (Tue, 05 May 2009)
Log Message:
-----------
SCI: Simplified internal_stringfrag_strcmp and internal_stringfrag_strncmp
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/stringfrag.cpp
Modified: scummvm/trunk/engines/sci/engine/stringfrag.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/stringfrag.cpp 2009-05-05 12:15:07 UTC (rev 40322)
+++ scummvm/trunk/engines/sci/engine/stringfrag.cpp 2009-05-05 12:20:28 UTC (rev 40323)
@@ -342,28 +342,21 @@
}
int internal_stringfrag_strcmp(EngineState *s, reg_t *s1, reg_t *s2) {
+ int c1, c2;
while (1) {
- if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0)
+ c1 = (byte)(s1->offset & 0xff00);
+ c2 = (byte)(s2->offset & 0xff00);
+ if (c1 != c2) // We found a difference
+ return c1 - c2;
+ else if (c1 == 0) // Both strings ended
return 0;
- if ((s1->offset & 0xff00) == 0)
- return -1;
- if ((s2->offset & 0xff00) == 0)
- return 1;
- if ((s1->offset & 0xff00) < (s2->offset & 0xff00))
- return -1;
- if ((s1->offset & 0xff00) > (s2->offset & 0xff00))
- return 1;
- if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0)
+ c1 = (byte)(s1->offset & 0x00ff);
+ c2 = (byte)(s2->offset & 0x00ff);
+ if (c1 != c2) // We found a difference
+ return c1 - c2;
+ else if (c1 == 0) // Both strings ended
return 0;
- if ((s1->offset & 0x00ff) == 0)
- return -1;
- if ((s2->offset & 0x00ff) == 0)
- return 1;
- if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff))
- return -1;
- if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff))
- return 1;
}
return 0;
@@ -377,32 +370,26 @@
}
int internal_stringfrag_strncmp(EngineState *s, reg_t *s1, reg_t *s2, int len) {
+ int c1, c2;
while (len) {
if (len--)
return 0;
- if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0)
+ c1 = (byte)(s1->offset & 0xff00);
+ c2 = (byte)(s2->offset & 0xff00);
+ if (c1 != c2) // We found a difference
+ return c1 - c2;
+ else if (c1 == 0) // Both strings ended
return 0;
- if ((s1->offset & 0xff00) == 0)
- return -1;
- if ((s2->offset & 0xff00) == 0)
- return 1;
- if ((s1->offset & 0xff00) < (s2->offset & 0xff00))
- return -1;
- if ((s1->offset & 0xff00) > (s2->offset & 0xff00))
- return 1;
if (len--)
return 0;
- if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0)
+
+ c1 = (byte)(s1->offset & 0x00ff);
+ c2 = (byte)(s2->offset & 0x00ff);
+ if (c1 != c2) // We found a difference
+ return c1 - c2;
+ else if (c1 == 0) // Both strings ended
return 0;
- if ((s1->offset & 0x00ff) == 0)
- return -1;
- if ((s2->offset & 0x00ff) == 0)
- return 1;
- if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff))
- return -1;
- if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff))
- return 1;
}
return 0;
@@ -416,4 +403,3 @@
}
} // end of namespace Sci
-
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