[genius] Wed Mar 21 15:39:04 2012 Jiri (George) Lebl <jirka 5z com>



commit 9c7e60680dc96d4b3eadc2bdd7a20428df032eb4
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Wed Mar 21 15:39:15 2012 -0500

    Wed Mar 21 15:39:04 2012  Jiri (George) Lebl <jirka 5z com>
    
    	* src/*.[ch]: mark a bunch of functions as pure.  Probably doesn't
    	  help with optimization, but it might.

 ChangeLog     |    5 +++++
 src/dict.c    |   25 ++++++++++++++-----------
 src/dict.h    |   16 ++++++++--------
 src/eval.c    |    5 +++--
 src/eval.h    |    2 +-
 src/matrixw.h |    6 +++---
 src/mpwrap.c  |   16 ++++++++--------
 src/mpwrap.h  |    8 ++++----
 8 files changed, 46 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 584df39..644ce41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Mar 21 15:39:04 2012  Jiri (George) Lebl <jirka 5z com>
+
+	* src/*.[ch]: mark a bunch of functions as pure.  Probably doesn't
+	  help with optimization, but it might.
+
 Tue Mar 20 13:13:48 2012  Jiri (George) Lebl <jirka 5z com>
 
 	* help/*/figures/*.eps: remove .eps figures, there is no need for
diff --git a/src/dict.c b/src/dict.c
index 123355b..c8487ed 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -48,7 +48,7 @@ extern const char *genius_operators[];
 
 /*return current context number (0 is global, -1 is uninitialized)*/
 int
-d_curcontext (void)
+d_curcontext (void) /* PURE! no side effects*/
 {
 	return context.top;
 }
@@ -418,7 +418,7 @@ d_setvalue (GelToken *id, GelETree *value)
 
 /*lookup a function in the dictionary in the current context*/
 GelEFunc *
-d_lookup_local(GelToken *id)
+d_lookup_local(GelToken *id) /* PURE! no side effects*/
 {
 	GelEFunc *func;
 
@@ -437,7 +437,7 @@ d_lookup_local(GelToken *id)
 
 /*lookup a function in the dictionary NOT in the current context*/
 GelEFunc *
-d_lookup_global_up1(GelToken *id)
+d_lookup_global_up1(GelToken *id)/* PURE! no side effects*/
 {
 	GSList *li;
 
@@ -459,7 +459,7 @@ d_lookup_global_up1(GelToken *id)
 
 /*lookup a function in the dictionary but only in the toplevel context */
 GelEFunc *
-d_lookup_only_global (GelToken *id)
+d_lookup_only_global (GelToken *id)/* PURE! no side effects*/
 {
 	GSList *li;
 	GelEFunc *func;
@@ -482,7 +482,7 @@ d_lookup_only_global (GelToken *id)
 
 /*lookup a function in the dictionary*/
 GelEFunc *
-d_lookup_global (GelToken *id)
+d_lookup_global (GelToken *id)/* PURE! no side effects*/
 {
 	GSList *li;
 	
@@ -874,7 +874,7 @@ d_popcontext (void)
 
 /*gimme the current dictinary*/
 GSList *
-d_getcontext (void)
+d_getcontext (void)/* PURE! no side effects*/
 {
 	if (context.top == -1)
 		return NULL;
@@ -885,7 +885,7 @@ d_getcontext (void)
 }
 
 GelContextFrame *
-d_get_all_contexts (void)
+d_get_all_contexts (void)/* PURE! no side effects*/
 {
 	if (context.top == -1)
 		return NULL;
@@ -895,7 +895,7 @@ d_get_all_contexts (void)
 
 /*gimme the current global dictinary*/
 GSList *
-d_getcontext_global (void)
+d_getcontext_global (void)/* PURE! no side effects*/
 {
 	if (context.top == -1) {
 		return NULL;
@@ -905,8 +905,9 @@ d_getcontext_global (void)
 	}
 }
 
+static int lowercase_ascii_sum_square (const char *id) G_GNUC_PURE;
 static int
-lowercase_ascii_sum_square (const char *id)
+lowercase_ascii_sum_square (const char *id) 
 {
 	int sum = 0;
 	int i;
@@ -917,8 +918,9 @@ lowercase_ascii_sum_square (const char *id)
 	return sum;
 }
 
+static int lowercase_ascii_sum (const char *id) G_GNUC_PURE;
 static int
-lowercase_ascii_sum (const char *id)
+lowercase_ascii_sum (const char *id) 
 {
 	int sum = 0;
 	int i;
@@ -928,8 +930,9 @@ lowercase_ascii_sum (const char *id)
 	return sum;
 }
 
+static int lowercase_kronecker_difference (const char *id1, const char *id2) G_GNUC_PURE;
 static int
-lowercase_kronecker_difference (const char *id1, const char *id2)
+lowercase_kronecker_difference (const char *id1, const char *id2) 
 {
 	int sum = 0;
 	int i;
diff --git a/src/dict.h b/src/dict.h
index 3278fb9..a440957 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -38,7 +38,7 @@ struct _GelContextFrame  {
 
 
 /*return current context number (0 is global, -1 is uninitialized)*/
-int d_curcontext(void);
+int d_curcontext(void) G_GNUC_PURE;
 
 /*make builtin function and return it*/
 GelEFunc * d_makebifunc(GelToken *id, GelBIFunction f, int nargs);
@@ -83,12 +83,12 @@ void d_set_ref(GelEFunc *n,GelEFunc *ref);
 /*lookup a function in the dictionary, either the whole thing, or just the
   current context otherwise*/
 /*lookup a function in the dictionary in the current context*/
-GelEFunc * d_lookup_local(GelToken *id);
-GelEFunc * d_lookup_global_up1(GelToken *id);
-GelEFunc * d_lookup_only_global (GelToken *id);
+GelEFunc * d_lookup_local(GelToken *id) G_GNUC_PURE;
+GelEFunc * d_lookup_global_up1(GelToken *id) G_GNUC_PURE;
+GelEFunc * d_lookup_only_global (GelToken *id) G_GNUC_PURE;
 /*lookup a function in the dictionary, if there are more return the one in the
   highest context*/
-GelEFunc * d_lookup_global (GelToken *id);
+GelEFunc * d_lookup_global (GelToken *id) G_GNUC_PURE;
 
 GelToken * d_intern (const char *id);
 
@@ -115,14 +115,14 @@ gboolean d_addcontext (GelEFunc *func);
 void d_popcontext(void);
 
 /*gimme the current dictinary*/
-GSList * d_getcontext (void);
+GSList * d_getcontext (void) G_GNUC_PURE;
 
 /* this is a list of lists of the context stack,
  * Also it is a pointer to the current context frame */
-GelContextFrame * d_get_all_contexts (void);
+GelContextFrame * d_get_all_contexts (void) G_GNUC_PURE;
 
 /*gimme the current global dictinary*/
-GSList * d_getcontext_global (void);
+GSList * d_getcontext_global (void) G_GNUC_PURE;
 GSList * d_find_similar_globals (const char *id);
 
 /* Put on subst local var list for this current stack */
diff --git a/src/eval.c b/src/eval.c
index 2f08244..9503b32 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1390,7 +1390,7 @@ static int
 logicalxorop(GelCtx *ctx, GelETree *n, GelETree *l, GelETree *r)
 {
 	gboolean bad_node = FALSE;
-	gboolean ret = gel_isnodetrue (l, &bad_node) != gel_isnodetrue (r,& bad_node);
+	gboolean ret = gel_isnodetrue (l, &bad_node) != gel_isnodetrue (r, &bad_node);
 
 	if G_UNLIKELY (bad_node || gel_error_num) {
 		gel_error_num = GEL_NO_ERROR;
@@ -2363,7 +2363,7 @@ gel_mod_node (GelCtx *ctx, GelETree *n)
 
 /*return TRUE if node is true (a number node !=0), false otherwise*/
 gboolean
-gel_isnodetrue (GelETree *n, gboolean *bad_node)
+gel_isnodetrue (GelETree *n, gboolean *bad_node) /*PURE!*/
 {
 	switch (n->type) {
 	case GEL_NULL_NODE:
@@ -3492,6 +3492,7 @@ iter_derefvarop(GelCtx *ctx, GelETree *n)
 	return;
 
 /*returns 0 if all numeric (or bool if bool_ok), 1 if numeric/matrix/null, 2 if contains string, 3 otherwise*/
+static int arglevel (GelETree *r, int cnt, gboolean bool_ok) G_GNUC_PURE;
 static int
 arglevel (GelETree *r, int cnt, gboolean bool_ok)
 {
diff --git a/src/eval.h b/src/eval.h
index dc8d6e3..f093a5d 100644
--- a/src/eval.h
+++ b/src/eval.h
@@ -101,7 +101,7 @@ GelETree * gel_eval_etree(GelCtx *ctx, GelETree *etree);
 
 /*return TRUE if node is true (a number node !=0, or nonempty string),
   false otherwise*/
-int gel_isnodetrue(GelETree *n, int *bad_node);
+int gel_isnodetrue(GelETree *n, int *bad_node) G_GNUC_PURE;
 
 /*call a function (arguments should have already been evaluated)*/
 GelETree * gel_funccall(GelCtx *ctx, GelEFunc *func, GelETree **args, int nargs);
diff --git a/src/matrixw.h b/src/matrixw.h
index 593c6c5..9c70964 100644
--- a/src/matrixw.h
+++ b/src/matrixw.h
@@ -134,7 +134,7 @@ extern GelETree *the_zero;
 #define gel_matrixw_elements(a) ((a)->regw*(a)->regh)
 
 /*get the value at, make sure it's in the range*/
-G_INLINE_FUNC GelETree *gel_matrixw_index(GelMatrixW *m, int x, int y);
+G_INLINE_FUNC GelETree *gel_matrixw_index(GelMatrixW *m, int x, int y) G_GNUC_PURE;
 /* Keep up to date with the one in the .c file */
 #ifdef G_CAN_INLINE
 G_INLINE_FUNC GelETree *
@@ -145,7 +145,7 @@ gel_matrixw_index(GelMatrixW *m, int x, int y) {
 #endif
 
 /*get the value at, make sure it's in the range*/
-G_INLINE_FUNC GelETree *gel_matrixw_vindex(GelMatrixW *m, int i);
+G_INLINE_FUNC GelETree *gel_matrixw_vindex(GelMatrixW *m, int i) G_GNUC_PURE;
 /* Keep up to date with the one in the .c file */
 #ifdef G_CAN_INLINE
 G_INLINE_FUNC GelETree *
@@ -164,7 +164,7 @@ gel_matrixw_vindex(GelMatrixW *m, int i) {
 #endif
 
 /*get the value at, make sure it's in the range*/
-G_INLINE_FUNC GelETree *gel_matrixw_get_vindex(GelMatrixW *m, int i);
+G_INLINE_FUNC GelETree *gel_matrixw_get_vindex(GelMatrixW *m, int i) G_GNUC_PURE;
 /* Keep up to date with the one in the .c file */
 #ifdef G_CAN_INLINE
 G_INLINE_FUNC GelETree *
diff --git a/src/mpwrap.c b/src/mpwrap.c
index 363aa70..215bf69 100644
--- a/src/mpwrap.c
+++ b/src/mpwrap.c
@@ -292,8 +292,8 @@ static inline void mpwl_init_type(MpwRealNum *op,int type);
 
 static inline void mpwl_free(MpwRealNum *op);
 
-static inline int mpwl_sgn (MpwRealNum *op);
-static inline int mpwl_zero_p (MpwRealNum *op);
+static inline int mpwl_sgn (MpwRealNum *op) G_GNUC_PURE;
+static inline int mpwl_zero_p (MpwRealNum *op) G_GNUC_PURE;
 
 static long mpwl_get_exp(MpwRealNum *op);
 
@@ -686,7 +686,7 @@ mpwl_sgn(MpwRealNum *op)
 }
 
 static inline int
-mpwl_zero_p (MpwRealNum *op)
+mpwl_zero_p (MpwRealNum *op) /* PURE!*/
 {
 	switch(op->type) {
 	case MPW_FLOAT: return mpfr_zero_p (op->data.fval);
@@ -3456,7 +3456,7 @@ mpw_peek_imag_mpf (mpw_ptr op)
 }
 
 int
-mpw_sgn(mpw_ptr op)
+mpw_sgn(mpw_ptr op) 
 {
 	if G_LIKELY (MPW_IS_REAL (op)) {
 		return mpwl_sgn(op->r);
@@ -3468,13 +3468,13 @@ mpw_sgn(mpw_ptr op)
 }
 
 int
-mpw_re_sgn(mpw_ptr op)
+mpw_re_sgn(mpw_ptr op) /* PURE */
 {
 	return mpwl_sgn(op->r);
 }
 
 int
-mpw_im_sgn(mpw_ptr op)
+mpw_im_sgn(mpw_ptr op) /* PURE */
 {
 	return mpwl_sgn(op->i);
 }
@@ -4161,7 +4161,7 @@ mpw_odd_p(mpw_ptr op)
 
 /* exact zero, not a float! */
 gboolean
-mpw_exact_zero_p (mpw_ptr op)
+mpw_exact_zero_p (mpw_ptr op) /* PURE! */
 {
 	if (MPW_IS_REAL (op) &&
 	    (op->r == gel_zero ||
@@ -4175,7 +4175,7 @@ mpw_exact_zero_p (mpw_ptr op)
 }
 
 gboolean
-mpw_zero_p (mpw_ptr op)
+mpw_zero_p (mpw_ptr op) /* PURE!*/
 {
 	if ((op->r == gel_zero || mpwl_zero_p (op->r)) &&
 	    (op->i == gel_zero || mpwl_zero_p (op->i))) {
diff --git a/src/mpwrap.h b/src/mpwrap.h
index e5404f3..9ebbf09 100644
--- a/src/mpwrap.h
+++ b/src/mpwrap.h
@@ -171,9 +171,9 @@ void mpw_abs_sq(mpw_ptr rop,mpw_ptr op);
 int mpw_sgn(mpw_ptr op);
 
 /* sign of the real part */
-int mpw_re_sgn(mpw_ptr op);
+int mpw_re_sgn(mpw_ptr op) G_GNUC_PURE;
 /* sign of the im part */
-int mpw_im_sgn(mpw_ptr op);
+int mpw_im_sgn(mpw_ptr op) G_GNUC_PURE;
 
 void mpw_neg(mpw_ptr rop,mpw_ptr op);
 
@@ -185,10 +185,10 @@ void mpw_sub_ui(mpw_ptr rop,mpw_ptr op, unsigned long i);
 void mpw_ui_sub(mpw_ptr rop,unsigned long i, mpw_ptr op);
 
 /* exact zero, not a float! */
-gboolean mpw_exact_zero_p (mpw_ptr op);
+gboolean mpw_exact_zero_p (mpw_ptr op) G_GNUC_PURE;
 
 /* any zero will do */
-gboolean mpw_zero_p (mpw_ptr op);
+gboolean mpw_zero_p (mpw_ptr op) G_GNUC_PURE;
 
 void mpw_mul(mpw_ptr rop,mpw_ptr op1, mpw_ptr op2);
 void mpw_mul_ui(mpw_ptr rop,mpw_ptr op, unsigned int i);



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