gnumeric r17096 - in trunk: . plugins/fn-lookup
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r17096 - in trunk: . plugins/fn-lookup
- Date: Mon, 26 Jan 2009 14:17:39 +0000 (UTC)
Author: mortenw
Date: Mon Jan 26 14:17:39 2009
New Revision: 17096
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17096&view=rev
Log:
2009-01-26 Morten Welinder <terra gnome org>
* functions.c (find_compare_type_valid): Floats should not match
bools.
(get_linear_lookup_cache): Create a separate cache for looking up
bools.
Modified:
trunk/NEWS
trunk/plugins/fn-lookup/ChangeLog
trunk/plugins/fn-lookup/functions.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Mon Jan 26 14:17:39 2009
@@ -81,6 +81,7 @@
* Fix loop while loading lotus file. [#568917]
* Fix performance problem in dependency tracking given large
number of large ranges. [#567389]
+ * Fix VLOOKUP and HLOOKUP for bools.
--------------------------------------------------------------------------
Gnumeric 1.9.3
Modified: trunk/plugins/fn-lookup/functions.c
==============================================================================
--- trunk/plugins/fn-lookup/functions.c (original)
+++ trunk/plugins/fn-lookup/functions.c Mon Jan 26 14:17:39 2009
@@ -57,6 +57,7 @@
static GOMemChunk *lookup_float_pool;
static GHashTable *linear_lookup_string_cache;
static GHashTable *linear_lookup_float_cache;
+static GHashTable *linear_lookup_bool_cache;
static void
clear_caches (void)
@@ -70,6 +71,9 @@
g_hash_table_destroy (linear_lookup_float_cache);
linear_lookup_float_cache = NULL;
+ g_hash_table_destroy (linear_lookup_bool_cache);
+ linear_lookup_bool_cache = NULL;
+
g_string_chunk_free (lookup_string_pool);
lookup_string_pool = NULL;
@@ -100,13 +104,18 @@
(GEqualFunc)gnm_sheet_range_equal,
(GDestroyNotify)gnm_sheet_range_free,
(GDestroyNotify)g_hash_table_destroy);
+ linear_lookup_bool_cache = g_hash_table_new_full
+ ((GHashFunc)gnm_sheet_range_hash,
+ (GEqualFunc)gnm_sheet_range_equal,
+ (GDestroyNotify)gnm_sheet_range_free,
+ (GDestroyNotify)g_hash_table_destroy);
}
/* -------------------------------------------------------------------------- */
static GHashTable *
get_linear_lookup_cache (GnmFuncEvalInfo *ei,
- GnmValue const *data, gboolean stringp,
+ GnmValue const *data, GnmValueType datatype,
gboolean *brand_new)
{
GnmSheetRange sr;
@@ -126,14 +135,19 @@
create_caches ();
- cache = stringp
- ? linear_lookup_string_cache
- : linear_lookup_float_cache;
+ switch (datatype) {
+ case VALUE_STRING: cache = linear_lookup_string_cache; break;
+ case VALUE_FLOAT: cache = linear_lookup_float_cache; break;
+ case VALUE_BOOLEAN: cache = linear_lookup_bool_cache; break;
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
h = g_hash_table_lookup (cache, &sr);
*brand_new = (h == NULL);
if (*brand_new) {
- if (stringp)
+ if (datatype == VALUE_STRING)
h = g_hash_table_new (g_str_hash, g_str_equal);
else
h = g_hash_table_new ((GHashFunc)gnm_float_hash,
@@ -164,10 +178,7 @@
if (find->type == val->type)
return TRUE;
- /* FIXME: what about number vs. bool? */
-
- if (VALUE_IS_NUMBER (find) && VALUE_IS_NUMBER (val))
- return TRUE;
+ /* Note: floats do not match bools. */
return FALSE;
}
@@ -264,7 +275,7 @@
char *sc;
gboolean found, brand_new;
- h = get_linear_lookup_cache (ei, data, TRUE, &brand_new);
+ h = get_linear_lookup_cache (ei, data, VALUE_STRING, &brand_new);
if (!h)
return -2;
@@ -305,7 +316,7 @@
gnm_float f;
gboolean found, brand_new;
- h = get_linear_lookup_cache (ei, data, FALSE, &brand_new);
+ h = get_linear_lookup_cache (ei, data, find->type, &brand_new);
if (!h)
return -2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]