aboutsummaryrefslogtreecommitdiffstats
path: root/storage.h
diff options
context:
space:
mode:
authorbjj <bjj>2006-09-07 00:55:02 +0000
committerbjj <bjj>2006-09-07 00:55:02 +0000
commitcc1f9810f4e6e0aa8eb496a42f97656f1cd4fd70 (patch)
tree8f0a1c20abe5da4a1c131b22fc63cbe514ded77a /storage.h
parent468c33fcc527c6b34d9201e906a2197439c07cab (diff)
downloadmoo-cvs-cc1f9810f4e6e0aa8eb496a42f97656f1cd4fd70.tar.gz
moo-cvs-cc1f9810f4e6e0aa8eb496a42f97656f1cd4fd70.tar.xz
moo-cvs-cc1f9810f4e6e0aa8eb496a42f97656f1cd4fd70.zip
Add new MEMO_STRLEN option which uses the refcounting mechanism to
store strlen with strings. This is basically free, since most string allocations are rounded up by malloc anyway. This saves lots of cycles computing strlen. (The change is originally from jitmoo, where I wanted inline range checks for string ops).
Diffstat (limited to 'storage.h')
-rw-r--r--storage.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/storage.h b/storage.h
index 11ca34a..1bec770 100644
--- a/storage.h
+++ b/storage.h
@@ -47,17 +47,35 @@ extern void myfree(void *where, Memory_Type type);
extern void *mymalloc(unsigned size, Memory_Type type);
extern void *myrealloc(void *where, unsigned size, Memory_Type type);
-static inline void /* XXX was extern, fix for non-gcc compilers */
+static inline void /* XXX was extern, fix for non-gcc compilers */
free_str(const char *s)
{
if (delref(s) == 0)
myfree((void *) s, M_STRING);
}
+#ifdef MEMO_STRLEN
+/*
+ * Using the same mechanism as ref_count.h uses to hide Value ref counts,
+ * keep a memozied strlen in the storage with the string.
+ */
+#define memo_strlen(X) ((void)0, (((int *)(X))[-2]))
+#else
+#define memo_strlen(X) strlen(X)
+
+#endif /* MEMO_STRLEN */
+
#endif /* Storage_h */
/*
* $Log$
+ * Revision 1.6 2006/09/07 00:55:02 bjj
+ * Add new MEMO_STRLEN option which uses the refcounting mechanism to
+ * store strlen with strings. This is basically free, since most string
+ * allocations are rounded up by malloc anyway. This saves lots of cycles
+ * computing strlen. (The change is originally from jitmoo, where I wanted
+ * inline range checks for string ops).
+ *
* Revision 1.5 1998/12/14 13:19:00 nop
* Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims
*