gnumeric r17144 - trunk/plugins/excel



Author: mortenw
Date: Wed Feb 18 16:31:43 2009
New Revision: 17144
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17144&view=rev

Log:
2009-02-18  Morten Welinder  <terra gnome org>

	* ms-formula-write.c (do_excel_write_prep_expr): Use
	excel_func_by_name hash table instead of linear search.

	* ms-excel-read.c (excel_read_init): Set up new hash table
	excel_func_by_name.



Modified:
   trunk/plugins/excel/ChangeLog
   trunk/plugins/excel/formula-types.h
   trunk/plugins/excel/ms-excel-read.c
   trunk/plugins/excel/ms-formula-read.c
   trunk/plugins/excel/ms-formula-write.c

Modified: trunk/plugins/excel/formula-types.h
==============================================================================
--- trunk/plugins/excel/formula-types.h	(original)
+++ trunk/plugins/excel/formula-types.h	Wed Feb 18 16:31:43 2009
@@ -103,6 +103,7 @@
 } ExcelFunc;
 
 extern ExcelFuncDesc const excel_func_desc[];
+extern GHashTable *excel_func_by_name;
 extern int excel_func_desc_size;
 
 #endif /* GNM_EXCEL_FORMULA_TYPES_H */

Modified: trunk/plugins/excel/ms-excel-read.c
==============================================================================
--- trunk/plugins/excel/ms-excel-read.c	(original)
+++ trunk/plugins/excel/ms-excel-read.c	Wed Feb 18 16:31:43 2009
@@ -35,6 +35,7 @@
 #include "ms-excel-util.h"
 #include "ms-excel-xf.h"
 #include "ms-pivot.h"
+#include "formula-types.h"
 
 #include <workbook.h>
 #include <workbook-view.h>
@@ -6771,13 +6772,27 @@
 void
 excel_read_init (void)
 {
+	int i;
+
 	excel_builtin_formats [0x0e] = go_format_builtins [GO_FORMAT_DATE][0];
 	excel_builtin_formats [0x0f] = go_format_builtins [GO_FORMAT_DATE][2];
 	excel_builtin_formats [0x10] = go_format_builtins [GO_FORMAT_DATE][4];
 	excel_builtin_formats [0x16] = go_format_builtins [GO_FORMAT_DATE][20];
+
+	excel_func_by_name = g_hash_table_new (g_str_hash, g_str_equal);
+	for (i = 0; i < excel_func_desc_size; i++) {
+		const ExcelFuncDesc *efd = excel_func_desc + i;
+		const char *name = efd->name;
+		g_assert (g_hash_table_lookup (excel_func_by_name, name) ==
+			  NULL);
+		g_hash_table_insert (excel_func_by_name,
+				     (gpointer)name,
+				     (gpointer)efd);
+	}
 }
 
 void
 excel_read_cleanup (void)
 {
+	g_hash_table_destroy (excel_func_by_name);
 }

Modified: trunk/plugins/excel/ms-formula-read.c
==============================================================================
--- trunk/plugins/excel/ms-formula-read.c	(original)
+++ trunk/plugins/excel/ms-formula-read.c	Wed Feb 18 16:31:43 2009
@@ -469,8 +469,8 @@
 /* 379 */ { "RTD",		 2,  5, XL_STD, 1, 'V', "V" },
 /* 380 */ { "ISHYPERLINK",       1,  1, XL_STD, 1, 'V', "V" }
 };
-
 int excel_func_desc_size = G_N_ELEMENTS (excel_func_desc);
+GHashTable *excel_func_by_name = NULL;
 
 static GnmExpr const *
 xl_expr_err (ExcelReadSheet const *esheet, int col, int row,

Modified: trunk/plugins/excel/ms-formula-write.c
==============================================================================
--- trunk/plugins/excel/ms-formula-write.c	(original)
+++ trunk/plugins/excel/ms-formula-write.c	Wed Feb 18 16:31:43 2009
@@ -109,27 +109,22 @@
 			return;
 
 		ef = g_new (ExcelFunc, 1);
-		if (!(func->flags & (GNM_FUNC_IS_PLACEHOLDER|GNM_FUNC_IS_WORKBOOK_LOCAL))) {
-			for (i = 0; i < excel_func_desc_size; i++)
-				if (!g_ascii_strcasecmp (excel_func_desc[i].name, func->name)) {
-					ef->efunc = excel_func_desc + i;
-					ef->idx = i;
-					ef->macro_name = NULL;
-					break;
-				}
-		} else
-			i = excel_func_desc_size;
-
-		if (i >= excel_func_desc_size) {
-			ef->efunc = NULL;
-			if (func->flags & GNM_FUNC_IS_WORKBOOK_LOCAL) {
-				ef->macro_name = g_strdup (func->name);
-				ef->idx = -1;
-			} else {
-				g_ptr_array_add (ewb->externnames, func);
-				ef->macro_name = NULL;
-				ef->idx = ewb->externnames->len;
-			}
+		ef->efunc = (func->flags & (GNM_FUNC_IS_PLACEHOLDER |
+					    GNM_FUNC_IS_WORKBOOK_LOCAL))
+			? NULL
+			: g_hash_table_lookup (excel_func_by_name,
+					       func->name);
+
+		if (ef->efunc) {
+			ef->idx = ef->efunc - excel_func_desc;
+			ef->macro_name = NULL;
+		} else if (func->flags & GNM_FUNC_IS_WORKBOOK_LOCAL) {
+			ef->macro_name = g_strdup (func->name);
+			ef->idx = -1;
+		} else {
+			g_ptr_array_add (ewb->externnames, func);
+			ef->macro_name = NULL;
+			ef->idx = ewb->externnames->len;
 		}
 		g_hash_table_insert (ewb->function_map, func, ef);
 		break;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]