From 1a9212d3b0401aed3472832c74bc3ee3cebd58ac Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Mon, 7 Dec 2009 12:53:29 +0000 Subject: [PATCH] * eet: Reduce convertion to FP, float and double with a little overhead. SVN revision: 44243 --- legacy/eet/ChangeLog | 1 + legacy/eet/src/lib/Eet_private.h | 17 +++++++---------- legacy/eet/src/lib/eet_dictionary.c | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/legacy/eet/ChangeLog b/legacy/eet/ChangeLog index 7d33c25438..6981be7214 100644 --- a/legacy/eet/ChangeLog +++ b/legacy/eet/ChangeLog @@ -273,3 +273,4 @@ 2009-12-07 Cedric BAIL * Fix error when retrieving a different float type than the stored one. + * Reduce convertion with a little memory overhead. diff --git a/legacy/eet/src/lib/Eet_private.h b/legacy/eet/src/lib/Eet_private.h index 9d0f2dcab8..fbbc6a4ebd 100644 --- a/legacy/eet/src/lib/Eet_private.h +++ b/legacy/eet/src/lib/Eet_private.h @@ -11,10 +11,10 @@ typedef enum _Eet_Convert_Type Eet_Convert_Type; enum _Eet_Convert_Type { - EET_D_NOT_CONVERTED, - EET_D_FLOAT, - EET_D_DOUBLE, - EET_D_FIXED_POINT + EET_D_NOT_CONVERTED = 0, + EET_D_FLOAT = 1 << 1, + EET_D_DOUBLE = 1 << 2, + EET_D_FIXED_POINT = 1 << 4 }; typedef struct _Eet_String Eet_String; @@ -30,12 +30,9 @@ struct _Eet_String int next; int prev; - union - { - float f; - double d; - Eina_F32p32 fp; - } convert; + float f; + double d; + Eina_F32p32 fp; Eet_Convert_Type type; }; diff --git a/legacy/eet/src/lib/eet_dictionary.c b/legacy/eet/src/lib/eet_dictionary.c index fdd51fc0a1..14db95faf6 100644 --- a/legacy/eet/src/lib/eet_dictionary.c +++ b/legacy/eet/src/lib/eet_dictionary.c @@ -260,13 +260,13 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *resu { if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE; - if (ed->all[index].type != EET_D_FLOAT) + if (!(ed->all[index].type & EET_D_FLOAT)) { const char *str; str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap; - if (!_eet_dictionary_string_get_float_cache(str, ed->all[index].len, &ed->all[index].convert.f)) + if (!_eet_dictionary_string_get_float_cache(str, ed->all[index].len, &ed->all[index].f)) { long long mantisse = 0; long exponent = 0; @@ -274,13 +274,13 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *resu if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE) return EINA_FALSE; - ed->all[index].convert.f = ldexpf((float) mantisse, exponent); + ed->all[index].f = ldexpf((float) mantisse, exponent); } - ed->all[index].type = EET_D_FLOAT; + ed->all[index].type |= EET_D_FLOAT; } - *result = ed->all[index].convert.f; + *result = ed->all[index].f; return EINA_TRUE; } @@ -289,13 +289,13 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *re { if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE; - if (ed->all[index].type != EET_D_DOUBLE) + if (!(ed->all[index].type & EET_D_DOUBLE)) { const char *str; str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap; - if (!_eet_dictionary_string_get_double_cache(str, ed->all[index].len, &ed->all[index].convert.d)) + if (!_eet_dictionary_string_get_double_cache(str, ed->all[index].len, &ed->all[index].d)) { long long mantisse = 0; long exponent = 0; @@ -303,13 +303,13 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *re if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE) return EINA_FALSE; - ed->all[index].convert.d = ldexp((double) mantisse, exponent); + ed->all[index].d = ldexp((double) mantisse, exponent); } - ed->all[index].type = EET_D_DOUBLE; + ed->all[index].type |= EET_D_DOUBLE; } - *result = ed->all[index].convert.d; + *result = ed->all[index].d; return EINA_TRUE; } @@ -318,7 +318,7 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int index, Eina_F32p32 *r { if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE; - if (ed->all[index].type != EET_D_FIXED_POINT) + if (!(ed->all[index].type & EET_D_FIXED_POINT)) { const char *str; Eina_F32p32 fp; @@ -328,11 +328,11 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int index, Eina_F32p32 *r if (!eina_convert_atofp(str, ed->all[index].len, &fp)) return EINA_FALSE; - ed->all[index].convert.fp = fp; - ed->all[index].type = EET_D_FIXED_POINT; + ed->all[index].fp = fp; + ed->all[index].type |= EET_D_FIXED_POINT; } - *result = ed->all[index].convert.fp; + *result = ed->all[index].fp; return EINA_TRUE; }