Alexandre Julliard : makedep: Sort makefile variables.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Mar 29 08:53:21 CDT 2016
Module: wine
Branch: master
Commit: 512c686be9b3eb952a8d6e49abae032f335bc1b8
URL: http://source.winehq.org/git/wine.git/?a=commit;h=512c686be9b3eb952a8d6e49abae032f335bc1b8
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Mar 29 12:27:17 2016 +0900
makedep: Sort makefile variables.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
tools/makedep.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/tools/makedep.c b/tools/makedep.c
index 9ad6e39..2a9782a 100644
--- a/tools/makedep.c
+++ b/tools/makedep.c
@@ -413,10 +413,15 @@ static void strarray_add_uniq( struct strarray *array, const char *str )
*/
static const char *strarray_get_value( const struct strarray *array, const char *name )
{
- unsigned int i;
+ int pos, res, min = 0, max = array->count / 2 - 1;
- for (i = 0; i < array->count; i += 2)
- if (!strcmp( array->str[i], name )) return array->str[i + 1];
+ while (min <= max)
+ {
+ pos = (min + max) / 2;
+ if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
+ if (res < 0) min = pos + 1;
+ else max = pos - 1;
+ }
return NULL;
}
@@ -428,17 +433,25 @@ static const char *strarray_get_value( const struct strarray *array, const char
*/
static void strarray_set_value( struct strarray *array, const char *name, const char *value )
{
- unsigned int i;
+ int i, pos, res, min = 0, max = array->count / 2 - 1;
- /* redefining a variable replaces the previous value */
- for (i = 0; i < array->count; i += 2)
+ while (min <= max)
{
- if (strcmp( array->str[i], name )) continue;
- array->str[i + 1] = value;
- return;
+ pos = (min + max) / 2;
+ if (!(res = strcmp( array->str[pos * 2], name )))
+ {
+ /* redefining a variable replaces the previous value */
+ array->str[pos * 2 + 1] = value;
+ return;
+ }
+ if (res < 0) min = pos + 1;
+ else max = pos - 1;
}
- strarray_add( array, name );
- strarray_add( array, value );
+ strarray_add( array, NULL );
+ strarray_add( array, NULL );
+ for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
+ array->str[min * 2] = name;
+ array->str[min * 2 + 1] = value;
}
More information about the wine-cvs
mailing list