Added two new alloca-based function macros, g_strdup_a and g_strconcat_a.
authorJeff Garzik <jgarzik@src.gnome.org>
Fri, 1 Jan 1999 23:35:26 +0000 (23:35 +0000)
committerJeff Garzik <jgarzik@src.gnome.org>
Fri, 1 Jan 1999 23:35:26 +0000 (23:35 +0000)
        * configure.in, glib.h:
        Added two new alloca-based function macros, g_strdup_a and
        g_strconcat_a.  These are stack-based and much faster than
        their g_malloc-based counterparts.  Kudos to Ulrich Drepper
        for help on this one.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
configure.in
glib.h
glib/glib.h

index a663de9..3493f5f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index a663de9..3493f5f 100644 (file)
@@ -1,3 +1,11 @@
+Fri Jan  1 17:09:19 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
+
+       * configure.in, glib.h:
+       Added two new alloca-based function macros, g_strdup_a and
+       g_strconcat_a.  These are stack-based and much faster than
+       their g_malloc-based counterparts.  Kudos to Ulrich Drepper
+       for help on this one.
+
 Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson <amundson@gtk.org>
 
         * Released GLib 1.1.11 
index 2b1bbd6..ea05878 100644 (file)
@@ -168,6 +168,12 @@ AC_HEADER_STDC
 
 # Checks for library functions.
 AC_FUNC_VPRINTF
+AC_FUNC_ALLOCA
+if test "x$ac_cv_func_alloca_works" = xyes; then
+       glib_have_alloca=yes
+else
+       glib_have_alloca=no
+fi
 
 AC_CHECK_FUNCS(atexit on_exit)
 
@@ -245,6 +251,7 @@ AC_CHECK_HEADERS(sys/time.h, AC_DEFINE(HAVE_SYS_TIME_H))
 AC_CHECK_HEADERS(sys/times.h, AC_DEFINE(HAVE_SYS_TIMES_H))
 AC_CHECK_HEADERS(unistd.h, AC_DEFINE(HAVE_UNISTD_H))
 AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
+AC_CHECK_HEADER(alloca.h, glib_have_alloca_h=yes, glib_have_alloca_h=no)
 
 # Check for some functions
 AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp poll)
@@ -866,6 +873,7 @@ _______EOF
        cat >>$outfile <<_______EOF
 $glib_atexit
 $glib_memmove
+$glib_alloca
 $glib_defines
 
 $glib_vacopy
@@ -1129,6 +1137,45 @@ if test x$glib_working_wctype = xno; then
 #define G_HAVE_BROKEN_WCTYPE 1"
 fi
 
+if test x$glib_have_alloca = xyes; then
+  glib_alloca="
+
+/* alloca support */"
+
+  if test x$glib_have_alloca_h = xyes; then
+    glib_alloca="\$glib_alloca
+#define G_HAVE_ALLOCA_H 1"
+  fi
+
+  glib_alloca="\$glib_alloca
+#define G_HAVE_ALLOCA 1
+
+/* BEGIN autoconf 2.13 alloca incantation
+        NOTE: Do not un-indent the #pragma below. */
+/* AIX requires this to be the first thing in the file.  */
+#ifdef __GNUC__
+# ifndef alloca
+#  define alloca __builtin_alloca
+# endif
+#else
+# if G_HAVE_ALLOCA_H
+#  include <alloca.h>
+# else
+#  ifdef _AIX
+ #pragma alloca
+#  else
+#   ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#   endif
+#  endif
+# endif
+#endif
+/* END autoconf 2.13 alloca incantation */
+
+
+"
+fi
+
 case x$enable_threads in
 xyes)  g_enable_threads_def="#define";;
 *)     g_enable_threads_def="#undef ";;
diff --git a/glib.h b/glib.h
index b6d178a..3e91c9b 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -1455,6 +1455,37 @@ gchar*    g_strescape            (gchar        *string);
 gpointer g_memdup              (gconstpointer mem,
                                 guint         byte_size);
 
+/* Macros for dynamic strings via fast stack allocation
+ * All macros take a special first argument: the target gchar* string
+ */
+#if G_HAVE_ALLOCA
+
+#  define g_strdup_a(newstr,str) G_STMT_START { \
+         const char *__old = (str);            \
+         char *__new;                          \
+         size_t __len = strlen (__old) + 1;    \
+         __new = alloca (__len);               \
+         memcpy (__new, __old, __len);         \
+         (newstr) = __new;                     \
+   } G_STMT_END
+
+#  define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
+         size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
+         size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
+         size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
+         char *__sptr, *__new = \
+               alloca (__len1 + __len2 + __len3 + 1); \
+         __sptr = __new; \
+         if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \
+         if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \
+         if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \
+         *__sptr = '\0'; \
+         (newstr) = __new; \
+   } G_STMT_END
+
+#endif /* G_HAVE_ALLOCA */
+
+
 /* NULL terminated string arrays.
  * g_strsplit() splits up string into max_tokens tokens at delim and
  * returns a newly allocated string array.
index b6d178a..3e91c9b 100644 (file)
@@ -1455,6 +1455,37 @@ gchar*    g_strescape            (gchar        *string);
 gpointer g_memdup              (gconstpointer mem,
                                 guint         byte_size);
 
+/* Macros for dynamic strings via fast stack allocation
+ * All macros take a special first argument: the target gchar* string
+ */
+#if G_HAVE_ALLOCA
+
+#  define g_strdup_a(newstr,str) G_STMT_START { \
+         const char *__old = (str);            \
+         char *__new;                          \
+         size_t __len = strlen (__old) + 1;    \
+         __new = alloca (__len);               \
+         memcpy (__new, __old, __len);         \
+         (newstr) = __new;                     \
+   } G_STMT_END
+
+#  define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
+         size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
+         size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
+         size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \
+         char *__sptr, *__new = \
+               alloca (__len1 + __len2 + __len3 + 1); \
+         __sptr = __new; \
+         if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \
+         if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \
+         if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \
+         *__sptr = '\0'; \
+         (newstr) = __new; \
+   } G_STMT_END
+
+#endif /* G_HAVE_ALLOCA */
+
+
 /* NULL terminated string arrays.
  * g_strsplit() splits up string into max_tokens tokens at delim and
  * returns a newly allocated string array.