mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Update strcmp implementation, to improve performance
JerryScript-DCO-1.0-Signed-off-by: Xin Hu Xin.A.Hu@intel.com
This commit is contained in:
parent
f6bd5afa42
commit
ba95cb010a
@ -156,43 +156,23 @@ CALL_PRAGMA (GCC diagnostic pop)
|
||||
/** Compare two strings. return an integer less than, equal to, or greater than zero
|
||||
if s1 is found, respectively, to be less than, to match, or be greater than s2. */
|
||||
int
|
||||
strcmp (const char *s1, const char *s2)
|
||||
strcmp (const char *str1, const char *str2)
|
||||
{
|
||||
size_t i;
|
||||
if (s1 == NULL)
|
||||
int s1;
|
||||
int s2;
|
||||
do
|
||||
{
|
||||
if (s2 != NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (s2 == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
s1 = *str1++;
|
||||
s2 = *str2++;
|
||||
|
||||
for (i = 0; s1[i]; i++)
|
||||
{
|
||||
if (s1[i] > s2[i])
|
||||
if (s1 == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (s1[i] < s2[i])
|
||||
{
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (s1 == s2);
|
||||
|
||||
if (s2[i])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return (s1 < s2) ? -1 : (s1 > s2 ? 1 : 0);
|
||||
}
|
||||
|
||||
/** Compare two strings. return an integer less than, equal to, or greater than zero
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user