[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.11-86-g9c5d6
From: |
Ludovic Courtès |
Subject: |
[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.11-86-g9c5d6aa |
Date: |
Fri, 31 Oct 2014 23:51:22 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=9c5d6aa9642891e571a7e7a2428c2084fe1058cf
The branch, stable-2.0 has been updated
via 9c5d6aa9642891e571a7e7a2428c2084fe1058cf (commit)
via a7bbba05838cabe2294f498e7008e1c51db6d664 (commit)
from 30c5982a9548a0ca0ea46111beb490f06d74a40a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9c5d6aa9642891e571a7e7a2428c2084fe1058cf
Author: Ludovic Courtès <address@hidden>
Date: Fri Oct 31 23:27:44 2014 +0100
Reduce C heap allocations in 'search-path'.
* libguile/load.c (scm_c_string_has_an_ext): Rename to...
(string_has_an_ext): ... this. Add docstring. Change
'str' to be an SCM, and remove 'len' parameter. Change loop body to
use 'scm_string_suffix_p'.
(search_path): Update accordingly.
commit a7bbba05838cabe2294f498e7008e1c51db6d664
Author: Ludovic Courtès <address@hidden>
Date: Fri Oct 31 22:53:04 2014 +0100
Use on-stack or GC-managed memory in 'search-path'.
* libguile/load.c (stringbuf_free): Remove.
(stringbuf_grow): Use 'scm_gc_malloc_pointerless' instead of
'scm_realloc'.
(search_path): Use stack-allocated INITIAL_BUFFER instead of
'scm_malloc'. Remove use of 'stringbuf_free'.
-----------------------------------------------------------------------
Summary of changes:
libguile/load.c | 57 ++++++++++++++++++++++++++----------------------------
1 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/libguile/load.c b/libguile/load.c
index 74ccd08..0a49066 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -403,24 +403,24 @@ SCM scm_listofnullstr;
/* Utility functions for assembling C strings in a buffer.
*/
-struct stringbuf {
+struct stringbuf
+{
char *buf, *ptr;
size_t buf_len;
};
static void
-stringbuf_free (void *data)
-{
- struct stringbuf *buf = (struct stringbuf *)data;
- free (buf->buf);
-}
-
-static void
stringbuf_grow (struct stringbuf *buf)
{
- size_t ptroff = buf->ptr - buf->buf;
- buf->buf_len *= 2;
- buf->buf = scm_realloc (buf->buf, buf->buf_len);
+ size_t ptroff, prev_len;
+ void *prev_buf = buf->buf;
+
+ prev_len = buf->buf_len;
+ ptroff = buf->ptr - buf->buf;
+
+ buf->buf_len *= 2;
+ buf->buf = scm_gc_malloc_pointerless (buf->buf_len, "search-path");
+ memcpy (buf->buf, prev_buf, prev_len);
buf->ptr = buf->buf + ptroff;
}
@@ -470,23 +470,22 @@ stringbuf_cat (struct stringbuf *buf, char *str)
}
}
-
+/* Return non-zero if STR is suffixed by a dot followed by one of
+ EXTENSIONS. */
static int
-scm_c_string_has_an_ext (char *str, size_t len, SCM extensions)
+string_has_an_ext (SCM str, SCM extensions)
{
for (; !scm_is_null (extensions); extensions = SCM_CDR (extensions))
{
- char *ext;
- size_t extlen;
- int match;
- ext = scm_to_locale_string (SCM_CAR (extensions));
- extlen = strlen (ext);
- match = (len > extlen && str[len - extlen - 1] == '.'
- && strncmp (str + (len - extlen), ext, extlen) == 0);
- free (ext);
- if (match)
- return 1;
+ SCM extension;
+
+ extension = SCM_CAR (extensions);
+ if (scm_is_true (scm_string_suffix_p (extension, str,
+ SCM_UNDEFINED, SCM_UNDEFINED,
+ SCM_UNDEFINED, SCM_UNDEFINED)))
+ return 1;
}
+
return 0;
}
@@ -558,6 +557,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM
require_exts,
char *filename_chars;
size_t filename_len;
SCM result = SCM_BOOL_F;
+ char initial_buffer[256];
if (scm_ilength (path) < 0)
scm_misc_error ("%search-path", "path is not a proper list: ~a",
@@ -576,8 +576,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM
require_exts,
if (is_absolute_file_name (filename))
{
if ((scm_is_false (require_exts) ||
- scm_c_string_has_an_ext (filename_chars, filename_len,
- extensions))
+ string_has_an_ext (filename, extensions))
&& stat (filename_chars, stat_buf) == 0
&& !(stat_buf->st_mode & S_IFDIR))
result = filename;
@@ -595,8 +594,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM
require_exts,
if (*endp == '.')
{
if (scm_is_true (require_exts) &&
- !scm_c_string_has_an_ext (filename_chars, filename_len,
- extensions))
+ !string_has_an_ext (filename, extensions))
{
/* This filename has an extension, but not one of the right
ones... */
@@ -619,9 +617,8 @@ search_path (SCM path, SCM filename, SCM extensions, SCM
require_exts,
if (scm_is_null (extensions))
extensions = scm_listofnullstr;
- buf.buf_len = 512;
- buf.buf = scm_malloc (buf.buf_len);
- scm_dynwind_unwind_handler (stringbuf_free, &buf, SCM_F_WIND_EXPLICITLY);
+ buf.buf_len = sizeof initial_buffer;
+ buf.buf = initial_buffer;
/* Try every path element.
*/
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.11-86-g9c5d6aa,
Ludovic Courtès <=