mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
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.
This commit is contained in:
parent
a7bbba0583
commit
9c5d6aa964
1 changed files with 13 additions and 16 deletions
|
@ -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
|
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))
|
for (; !scm_is_null (extensions); extensions = SCM_CDR (extensions))
|
||||||
{
|
{
|
||||||
char *ext;
|
SCM extension;
|
||||||
size_t extlen;
|
|
||||||
int match;
|
extension = SCM_CAR (extensions);
|
||||||
ext = scm_to_locale_string (SCM_CAR (extensions));
|
if (scm_is_true (scm_string_suffix_p (extension, str,
|
||||||
extlen = strlen (ext);
|
SCM_UNDEFINED, SCM_UNDEFINED,
|
||||||
match = (len > extlen && str[len - extlen - 1] == '.'
|
SCM_UNDEFINED, SCM_UNDEFINED)))
|
||||||
&& strncmp (str + (len - extlen), ext, extlen) == 0);
|
return 1;
|
||||||
free (ext);
|
|
||||||
if (match)
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,8 +576,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts,
|
||||||
if (is_absolute_file_name (filename))
|
if (is_absolute_file_name (filename))
|
||||||
{
|
{
|
||||||
if ((scm_is_false (require_exts) ||
|
if ((scm_is_false (require_exts) ||
|
||||||
scm_c_string_has_an_ext (filename_chars, filename_len,
|
string_has_an_ext (filename, extensions))
|
||||||
extensions))
|
|
||||||
&& stat (filename_chars, stat_buf) == 0
|
&& stat (filename_chars, stat_buf) == 0
|
||||||
&& !(stat_buf->st_mode & S_IFDIR))
|
&& !(stat_buf->st_mode & S_IFDIR))
|
||||||
result = filename;
|
result = filename;
|
||||||
|
@ -596,8 +594,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts,
|
||||||
if (*endp == '.')
|
if (*endp == '.')
|
||||||
{
|
{
|
||||||
if (scm_is_true (require_exts) &&
|
if (scm_is_true (require_exts) &&
|
||||||
!scm_c_string_has_an_ext (filename_chars, filename_len,
|
!string_has_an_ext (filename, extensions))
|
||||||
extensions))
|
|
||||||
{
|
{
|
||||||
/* This filename has an extension, but not one of the right
|
/* This filename has an extension, but not one of the right
|
||||||
ones... */
|
ones... */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue