aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-07-16 10:41:01 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-07-16 10:41:01 +0800
commit8d208b95bb0a9a240f0ac5a9110be1ebf550ac15 (patch)
tree7f08c696f8dc983525670aafbba9e1adbff8efd4
parent7f0ab8334b1dcdf8beb19ea28005ba6055c7bfc0 (diff)
downloadgsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar.gz
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar.bz2
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar.lz
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar.xz
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.tar.zst
gsoc2013-evolution-8d208b95bb0a9a240f0ac5a9110be1ebf550ac15.zip
Cast to a string type. (term_eval_castint): Cast to an int type.
2002-07-15 Not Zed <NotZed@Ximian.com> * e-sexp.c (term_eval_caststring): Cast to a string type. (term_eval_castint): Cast to an int type. (symbols[]): Add to symbol table. * e-memory.c: Some more profiling for epoolv's. svn path=/trunk/; revision=17474
-rw-r--r--e-util/ChangeLog6
-rw-r--r--e-util/e-memory.c16
-rw-r--r--e-util/e-sexp.c64
3 files changed, 83 insertions, 3 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 11984ec60e..788868c281 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,9 @@
+2002-07-15 Not Zed <NotZed@Ximian.com>
+
+ * e-sexp.c (term_eval_caststring): Cast to a string type.
+ (term_eval_castint): Cast to an int type.
+ (symbols[]): Add to symbol table.
+
2002-07-09 Dan Winship <danw@ximian.com>
* e-categories-config.c: #include <string.h>
diff --git a/e-util/e-memory.c b/e-util/e-memory.c
index 108a627076..17385fa7ba 100644
--- a/e-util/e-memory.c
+++ b/e-util/e-memory.c
@@ -32,7 +32,7 @@
/*#define MALLOC_CHECK*/
-/* #define PROFILE_POOLV */
+/*#define PROFILE_POOLV*/
#ifdef PROFILE_POOLV
#include <time.h>
@@ -871,6 +871,7 @@ static GPtrArray *poolv_table = NULL;
#ifdef PROFILE_POOLV
static gulong poolv_hits = 0;
static gulong poolv_misses = 0;
+static unsigned long poolv_mem, poolv_count;
#endif
#ifdef G_THREADS_ENABLED
@@ -937,6 +938,9 @@ e_poolv_new(unsigned int size)
p(printf("new poolv=%p\tsize=%d\n", poolv, sizeof(*poolv) + (size-1)*sizeof(char *)));
+#ifdef PROFILE_POOLV
+ poolv_count++;
+#endif
return poolv;
}
@@ -1018,9 +1022,10 @@ poolv_profile_update (void)
if (new_time - last_time < 5)
return;
- printf("poolv profile: %lu hits, %lu misses: %d%% hit rate\n",
+ printf("poolv profile: %lu hits, %lu misses: %d%% hit rate, memory: %lu, instances: %lu\n",
poolv_hits, poolv_misses,
- (int)(100.0 * ((double) poolv_hits / (double) (poolv_hits + poolv_misses))));
+ (int)(100.0 * ((double) poolv_hits / (double) (poolv_hits + poolv_misses))),
+ poolv_mem, poolv_count);
last_time = new_time;
}
@@ -1086,6 +1091,7 @@ e_poolv_set (EPoolv *poolv, int index, char *str, int freeit)
} else {
# ifdef PROFILE_POOLV
poolv_misses++;
+ poolv_mem += strlen(str);
poolv_profile_update ();
# endif
poolv->s[index] = e_mempool_strdup(poolv_mempool, str);
@@ -1101,6 +1107,7 @@ e_poolv_set (EPoolv *poolv, int index, char *str, int freeit)
} else {
# ifdef PROFILE_POOLV
poolv_misses++;
+ poolv_mem += strlen(str);
poolv_profile_update ();
# endif
poolv->s[index] = e_mempool_strdup(poolv_mempool, str);
@@ -1187,6 +1194,9 @@ e_poolv_destroy(EPoolv *poolv)
#endif
#endif
+#ifdef PROFILE_POOLV
+ poolv_count++;
+#endif
g_free(poolv);
}
diff --git a/e-util/e-sexp.c b/e-util/e-sexp.c
index 9dce281465..6487b1e024 100644
--- a/e-util/e-sexp.c
+++ b/e-util/e-sexp.c
@@ -51,6 +51,12 @@
time_t = (- time_t*)
Subtract time_t values from the first.
+ int = (cast-int string|int|bool)
+ Cast to an integer value.
+
+ string = (cast-string string|int|bool)
+ Cast to an string value.
+
Comparison operators:
bool = (< int int)
@@ -553,6 +559,62 @@ term_eval_sub(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data
return r;
}
+/* cast to int */
+static ESExpResult *
+term_eval_castint(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
+{
+ struct _ESExpResult *r;
+
+ if (argc != 1)
+ e_sexp_fatal_error(f, "Incorrect argument count to (int )");
+
+ r = e_sexp_result_new(f, ESEXP_RES_INT);
+ switch (argv[0]->type) {
+ case ESEXP_RES_INT:
+ r->value.number = argv[0]->value.number;
+ break;
+ case ESEXP_RES_BOOL:
+ r->value.number = argv[0]->value.bool != 0;
+ break;
+ case ESEXP_RES_STRING:
+ r->value.number = strtoul(argv[0]->value.string, 0, 10);
+ break;
+ default:
+ e_sexp_result_free(f, r);
+ e_sexp_fatal_error(f, "Invalid type in (cast-int )");
+ }
+
+ return r;
+}
+
+/* cast to string */
+static ESExpResult *
+term_eval_caststring(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
+{
+ struct _ESExpResult *r;
+
+ if (argc != 1)
+ e_sexp_fatal_error(f, "Incorrect argument count to (cast-string )");
+
+ r = e_sexp_result_new(f, ESEXP_RES_STRING);
+ switch (argv[0]->type) {
+ case ESEXP_RES_INT:
+ r->value.string = g_strdup_printf("%d", argv[0]->value.number);
+ break;
+ case ESEXP_RES_BOOL:
+ r->value.string = g_strdup_printf("%d", argv[0]->value.bool != 0);
+ break;
+ case ESEXP_RES_STRING:
+ r->value.string = g_strdup(argv[0]->value.string);
+ break;
+ default:
+ e_sexp_result_free(f, r);
+ e_sexp_fatal_error(f, "Invalid type in (int )");
+ }
+
+ return r;
+}
+
/* implements 'if' function */
static ESExpResult *
term_eval_if(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data)
@@ -991,6 +1053,8 @@ static struct {
{ "=", (ESExpFunc *)term_eval_eq, 1 },
{ "+", (ESExpFunc *)term_eval_plus, 0 },
{ "-", (ESExpFunc *)term_eval_sub, 0 },
+ { "cast-int", (ESExpFunc *)term_eval_castint, 0 },
+ { "cast-string", (ESExpFunc *)term_eval_caststring, 0 },
{ "if", (ESExpFunc *)term_eval_if, 1 },
{ "begin", (ESExpFunc *)term_eval_begin, 1 },
};