genius r739 - in trunk: . src
- From: jirka svn gnome org
- To: svn-commits-list gnome org
- Subject: genius r739 - in trunk: . src
- Date: Thu, 26 Feb 2009 08:27:22 +0000 (UTC)
Author: jirka
Date: Thu Feb 26 08:27:22 2009
New Revision: 739
URL: http://svn.gnome.org/viewvc/genius?rev=739&view=rev
Log:
Thu Feb 26 02:27:06 2009 Jiri (George) Lebl <jirka 5z com>
* src/eval.c, src/calc.c, src/dict.[ch], src/gnome-genius.h,
src/structs.h, src/symbolic.c: store uncompiled string in the
token, not in a separate hash table. This avoids extra lookups
during startup.
* src/calc.c: a bit more optimization for help initialization
Modified:
trunk/ChangeLog
trunk/src/calc.c
trunk/src/dict.c
trunk/src/dict.h
trunk/src/eval.c
trunk/src/gnome-genius.h
trunk/src/structs.h
trunk/src/symbolic.c
Modified: trunk/src/calc.c
==============================================================================
--- trunk/src/calc.c (original)
+++ trunk/src/calc.c Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2008 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
@@ -88,8 +88,6 @@
static gboolean ignore_end_parse_errors = FALSE;
static gboolean got_end_too_soon = FALSE;
-GHashTable *uncompiled = NULL;
-
/* stack ... has to be global:-( */
GSList *gel_parsestack=NULL;
@@ -129,32 +127,59 @@
return strcmp (h1->func, h2->func);
}
+static HelpCategory *get_category_cache = NULL;
+
+static HelpCategory *
+create_category (const char *category)
+{
+ HelpCategory *cat = g_new0 (HelpCategory, 1);
+ cat->category = g_strdup (category);
+ gel_categories = g_slist_append (gel_categories, cat);
+ get_category_cache = cat;
+ return cat;
+}
+
static HelpCategory *
get_category (const char *category, gboolean insert)
{
GSList *li;
+
+ if (get_category_cache != NULL &&
+ strcmp (get_category_cache->category, category) == 0)
+ return get_category_cache;
+
for (li = gel_categories; li != NULL; li = li->next) {
HelpCategory *cat = li->data;
- if (strcmp (cat->category, category) == 0)
+ if (cat != get_category_cache &&
+ strcmp (cat->category, category) == 0) {
+ get_category_cache = cat;
return cat;
+ }
}
if (insert) {
- HelpCategory *cat = g_new0 (HelpCategory, 1);
- cat->category = g_strdup (category);
- gel_categories = g_slist_append (gel_categories, cat);
- return cat;
+ return create_category (category);
} else {
return NULL;
}
}
+static GelHelp *get_help_cache = NULL;
+static const char *get_help_func_cache = NULL;
+
GelHelp *
get_help (const char *func, gboolean insert)
{
GelHelp *help;
- if (gel_helphash == NULL)
+ if (get_help_cache != NULL &&
+ /* just checking pointers is not safe, but it is fast,
+ * if pointers are same it is likely the string will be the same */
+ get_help_func_cache == func &&
+ strcmp (get_help_cache->func, func) == 0)
+ return get_help_cache;
+
+ if G_UNLIKELY (gel_helphash == NULL)
gel_helphash = g_hash_table_new (g_str_hash, g_str_equal);
help = g_hash_table_lookup (gel_helphash, func);
@@ -165,6 +190,11 @@
g_hash_table_insert (gel_helphash, help->func, help);
}
+ if (help != NULL) {
+ get_help_func_cache = func;
+ get_help_cache = help;
+ }
+
return help;
}
@@ -188,7 +218,8 @@
if (category == NULL)
return _("Uncategorized");
- cat = get_category (category, FALSE /* insert */);
+ cat = get_category (category,
+ FALSE /* insert */);
if (cat == NULL || cat->name == NULL)
return category;
else
@@ -236,7 +267,8 @@
return get_uncategorized_documented ();
}
- cat = get_category (category, FALSE /* insert */);
+ cat = get_category (category,
+ FALSE /* insert */);
if (cat == NULL) {
return NULL;
} else {
@@ -291,8 +323,15 @@
void
new_category (const char *category, const char *name, gboolean internal)
{
- HelpCategory *cat = get_category (category, TRUE /* insert */);
- g_free (cat->name);
+
+ HelpCategory *cat;
+
+ if (internal) {
+ cat = create_category (category);
+ } else {
+ cat = get_category (category, TRUE /* insert */);
+ g_free (cat->name);
+ }
cat->name = g_strdup (name);
cat->internal = internal;
}
@@ -301,7 +340,8 @@
remove_from_category (const char *func, const char *category)
{
GSList *li;
- HelpCategory *cat = get_category (category, TRUE /* insert */);
+ HelpCategory *cat = get_category (category,
+ TRUE /* insert */);
for (li = cat->funcs; li != NULL; li = li->next) {
char *f = li->data;
@@ -317,7 +357,8 @@
add_category (const char *func, const char *category)
{
GelHelp *help = get_help (func, TRUE /* insert */);
- HelpCategory *cat = get_category (category, TRUE /* insert */);
+ HelpCategory *cat = get_category (category,
+ TRUE /* insert */);
if (help->category != NULL) {
if (strcmp (help->category, category) == 0)
@@ -356,7 +397,7 @@
GelHelp *help, *ahelp;
help = get_help (func, TRUE /* insert */);
- if (help->aliasfor != NULL) {
+ if G_UNLIKELY (help->aliasfor != NULL) {
gel_errorout (_("Trying to set an alias for an alias"));
return;
}
@@ -399,17 +440,18 @@
char *p;
char *d;
- /*kill \n's \r's and ;'s (for compiled parsing purposes) */
- d = g_strdup(desc);
- if((p=strchr(d,'\n')))
- *p = '\0';
- if((p=strchr(d,'\r')))
- *p = '\0';
+ /*kill \n's and \r's (for compiled parsing purposes) */
+ d = g_strdup (desc);
+ for (p = d; *p != '\0'; p++) {
+ if (*p == '\n' || *p == '\r') {
+ *p = '\0';
+ break;
+ }
+ }
help = get_help (func, TRUE /* insert */);
g_free (help->description);
- help->description = g_strdup (d);
- g_free (d);
+ help->description = d;
}
void
@@ -436,6 +478,9 @@
if (help->category != NULL)
remove_from_category (func, help->category);
+ if (get_help_cache == help)
+ get_help_cache = NULL;
+
g_hash_table_remove (gel_helphash, func);
g_slist_free (help->aliases);
@@ -1784,8 +1829,7 @@
if (func->data.user) {
body = gel_compile_tree(func->data.user);
} else {
- body = g_strdup (g_hash_table_lookup (uncompiled,
- func->id));
+ body = g_strdup (func->id->uncompiled);
g_assert (body != NULL);
}
if (func->type == GEL_USER_FUNC) {
@@ -2150,9 +2194,7 @@
(last_func->extra_dict, func);
} else {
GelEFunc *func;
- if(!uncompiled)
- uncompiled = g_hash_table_new(NULL,NULL);
- g_hash_table_insert(uncompiled,tok,b2);
+ tok->uncompiled = b2;
if(type == GEL_USER_FUNC) {
func = d_makeufunc (tok, NULL, li, nargs, NULL);
func->vararg = vararg ? 1 : 0;
Modified: trunk/src/dict.c
==============================================================================
--- trunk/src/dict.c (original)
+++ trunk/src/dict.c Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2008 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
@@ -44,8 +44,6 @@
static GHashTable *dictionary;
-extern GHashTable *uncompiled;
-
extern const char *genius_toplevels[];
extern const char *genius_operators[];
Modified: trunk/src/dict.h
==============================================================================
--- trunk/src/dict.h (original)
+++ trunk/src/dict.h Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2007 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
@@ -125,14 +125,13 @@
#define D_ENSURE_USER_BODY(f) \
if G_UNLIKELY (f->data.user == NULL) { \
- g_assert (uncompiled != NULL); \
+ g_assert (f->id->uncompiled != NULL); \
f->data.user = \
- gel_decompile_tree (g_hash_table_lookup \
- (uncompiled, f->id)); \
+ gel_decompile_tree (f->id->uncompiled); \
+ f->id->uncompiled = NULL; \
/* On error give null tree */ \
if (f->data.user == NULL) \
f->data.user = gel_makenum_null (); \
- g_hash_table_remove (uncompiled, f->id); \
} \
Modified: trunk/src/eval.c
==============================================================================
--- trunk/src/eval.c (original)
+++ trunk/src/eval.c Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2008 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
@@ -56,8 +56,6 @@
static void _gel_make_free_evfi (void);
#endif /* ! MEM_DEBUG_FRIENDLY */
-extern GHashTable *uncompiled;
-
extern gboolean interrupted;
extern char *genius_params[];
Modified: trunk/src/gnome-genius.h
==============================================================================
--- trunk/src/gnome-genius.h (original)
+++ trunk/src/gnome-genius.h Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 2004-2007 George Lebl
+ * Copyright (C) 2004-2009 George Lebl
*
* Author: George Lebl
*
@@ -35,7 +35,6 @@
extern GeniusSetup genius_setup;
extern GtkWidget *genius_window;
-extern GHashTable *uncompiled;
extern calcstate_t calcstate;
void genius_interrupt_calc (void);
Modified: trunk/src/structs.h
==============================================================================
--- trunk/src/structs.h (original)
+++ trunk/src/structs.h Thu Feb 26 08:27:22 2009
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2004 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
@@ -81,10 +81,12 @@
GSList *refs;
/* For built-in parameters this is the get and set function
- * of type ParameterGetFunc and ParameterSetFunc */
+ * of type ParameterGetFunc and ParameterSetFunc. */
gpointer data1;
gpointer data2;
+ char *uncompiled;
+
guint8 protected_:1;
guint8 parameter:1;
guint8 built_in_parameter:1;
Modified: trunk/src/symbolic.c
==============================================================================
--- trunk/src/symbolic.c (original)
+++ trunk/src/symbolic.c Thu Feb 26 08:27:22 2009
@@ -1,11 +1,13 @@
/* GENIUS Calculator
- * Copyright (C) 2005 Jiri (George) Lebl
+ * Copyright (C) 1997-2009 Jiri (George) Lebl
*
* Author: Jiri (George) Lebl
*
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of Genius.
+ *
+ * Genius is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@@ -14,9 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
@@ -42,8 +42,6 @@
extern calcstate_t calcstate;
-extern GHashTable *uncompiled;
-
static GelETree * differentiate_expr (GelETree *expr, GelToken *xtok);
static GelETree * gel_differentiate_func1_expr (GelToken *tok);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]