mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
Optimize scm_lfwrite_substr', used by
scm_simple_format'.
Fixes <http://bugs.gnu.org/12033>. Reported by nalaginrut <nalaginrut@gmail.com>. * libguile/print.c (scm_i_display_substring): New function. * libguile/print.h (scm_i_display_substring): New internal declaration. * libguile/ports.c (scm_lfwrite_substr): Use it instead of `scm_display' + `scm_c_substring'.
This commit is contained in:
parent
ee26a9ebe2
commit
b908768a7e
3 changed files with 28 additions and 2 deletions
|
@ -1465,7 +1465,7 @@ scm_lfwrite_substr (SCM str, size_t start, size_t end, SCM port)
|
||||||
if (end == (size_t) -1)
|
if (end == (size_t) -1)
|
||||||
end = scm_i_string_length (str);
|
end = scm_i_string_length (str);
|
||||||
|
|
||||||
scm_display (scm_c_substring (str, start, end), port);
|
scm_i_display_substring (str, start, end, port);
|
||||||
|
|
||||||
if (pt->rw_random)
|
if (pt->rw_random)
|
||||||
pt->rw_active = SCM_PORT_WRITE;
|
pt->rw_active = SCM_PORT_WRITE;
|
||||||
|
|
|
@ -1167,6 +1167,29 @@ write_character (scm_t_wchar ch, SCM port, int string_escapes_p)
|
||||||
write_character_escaped (ch, string_escapes_p, port);
|
write_character_escaped (ch, string_escapes_p, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Display STR to PORT from START inclusive to END exclusive. */
|
||||||
|
void
|
||||||
|
scm_i_display_substring (SCM str, size_t start, size_t end, SCM port)
|
||||||
|
{
|
||||||
|
int narrow_p;
|
||||||
|
const char *buf;
|
||||||
|
size_t len, printed;
|
||||||
|
|
||||||
|
buf = scm_i_string_data (str);
|
||||||
|
len = end - start;
|
||||||
|
narrow_p = scm_i_is_narrow_string (str);
|
||||||
|
buf += start * (narrow_p ? sizeof (char) : sizeof (scm_t_wchar));
|
||||||
|
|
||||||
|
printed = display_string (buf, narrow_p, end - start, port,
|
||||||
|
PORT_CONVERSION_HANDLER (port));
|
||||||
|
|
||||||
|
if (SCM_UNLIKELY (printed < len))
|
||||||
|
scm_encoding_error (__func__, errno,
|
||||||
|
"cannot convert to output locale",
|
||||||
|
port, scm_c_string_ref (str, printed + start));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print an integer.
|
/* Print an integer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
#ifndef SCM_PRINT_H
|
#ifndef SCM_PRINT_H
|
||||||
#define SCM_PRINT_H
|
#define SCM_PRINT_H
|
||||||
|
|
||||||
/* Copyright (C) 1995,1996,1998,2000,2001, 2003, 2004, 2006, 2008, 2010 Free Software Foundation, Inc.
|
/* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2003, 2004, 2006, 2008,
|
||||||
|
* 2010, 2012 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -78,6 +79,8 @@ SCM_API SCM scm_print_options (SCM setting);
|
||||||
SCM_API SCM scm_make_print_state (void);
|
SCM_API SCM scm_make_print_state (void);
|
||||||
SCM_API void scm_free_print_state (SCM print_state);
|
SCM_API void scm_free_print_state (SCM print_state);
|
||||||
SCM_INTERNAL SCM scm_i_port_with_print_state (SCM port, SCM print_state);
|
SCM_INTERNAL SCM scm_i_port_with_print_state (SCM port, SCM print_state);
|
||||||
|
SCM_INTERNAL void scm_i_display_substring (SCM str, size_t start, size_t end,
|
||||||
|
SCM port);
|
||||||
SCM_API void scm_intprint (scm_t_intmax n, int radix, SCM port);
|
SCM_API void scm_intprint (scm_t_intmax n, int radix, SCM port);
|
||||||
SCM_API void scm_uintprint (scm_t_uintmax n, int radix, SCM port);
|
SCM_API void scm_uintprint (scm_t_uintmax n, int radix, SCM port);
|
||||||
SCM_API void scm_ipruk (char *hdr, SCM ptr, SCM port);
|
SCM_API void scm_ipruk (char *hdr, SCM ptr, SCM port);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue