Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Added two new alloca-based function macros, g_strdup_a and g_strconca…
Browse files Browse the repository at this point in the history
…t_a.

        * 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.
  • Loading branch information
Jeff Garzik committed Jan 1, 1999
1 parent b16bea1 commit 0e2f565
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-0
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-10
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-12
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-2
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-4
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-6
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog.pre-2-8
@@ -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
Expand Down
47 changes: 47 additions & 0 deletions configure.in
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -866,6 +873,7 @@ _______EOF
cat >>$outfile <<_______EOF
$glib_atexit
$glib_memmove
$glib_alloca
$glib_defines

$glib_vacopy
Expand Down Expand Up @@ -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 ";;
Expand Down
31 changes: 31 additions & 0 deletions glib.h
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions glib/glib.h
Expand Up @@ -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.
Expand Down

0 comments on commit 0e2f565

Please sign in to comment.