From b908768a7ec79f78def344c464186a51f55b69e8 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 20 Aug 2012 23:38:21 +0200 Subject: Optimize `scm_lfwrite_substr', used by `scm_simple_format'. Fixes . Reported by nalaginrut . * 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'. --- libguile/print.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libguile/print.c') diff --git a/libguile/print.c b/libguile/print.c index cb3c0b95a..647eed8cb 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -1167,6 +1167,29 @@ write_character (scm_t_wchar ch, SCM port, int string_escapes_p) 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. */ -- cgit v1.2.3