mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 04:10:18 +02:00
unread-char: inline conversion from codepoint to bytes
* libguile/ports.c (scm_ungetc_unlocked): Inline the conversion from codepoint to bytes for UTF-8 and latin-1 ports. Speeds up a numbers-reading test case by 100% (!).
This commit is contained in:
parent
8ac8e2dfeb
commit
be7ecef05c
1 changed files with 25 additions and 4 deletions
|
@ -2105,11 +2105,32 @@ scm_ungetc_unlocked (scm_t_wchar c, SCM port)
|
||||||
#define FUNC_NAME "scm_ungetc"
|
#define FUNC_NAME "scm_ungetc"
|
||||||
{
|
{
|
||||||
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
scm_t_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
scm_t_port_internal *pti = SCM_PORT_GET_INTERNAL (port);
|
||||||
char *result;
|
char *result;
|
||||||
char result_buf[10];
|
char result_buf[10];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = sizeof (result_buf);
|
len = sizeof (result_buf);
|
||||||
|
|
||||||
|
if (pti->encoding_mode == SCM_PORT_ENCODING_MODE_UTF8)
|
||||||
|
{
|
||||||
|
if (c < 0xf0)
|
||||||
|
{
|
||||||
|
result_buf[0] = (char) c;
|
||||||
|
result = result_buf;
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result =
|
||||||
|
(char *) u32_to_u8 ((uint32_t *) &c, 1, (uint8_t *) result_buf, &len);
|
||||||
|
}
|
||||||
|
else if (pti->encoding_mode == SCM_PORT_ENCODING_MODE_LATIN1 && c <= 0xff)
|
||||||
|
{
|
||||||
|
result_buf[0] = (char) c;
|
||||||
|
result = result_buf;
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
result = u32_conv_to_encoding (pt->encoding,
|
result = u32_conv_to_encoding (pt->encoding,
|
||||||
(enum iconv_ilseq_handler) pt->ilseq_handler,
|
(enum iconv_ilseq_handler) pt->ilseq_handler,
|
||||||
(uint32_t *) &c, 1, NULL,
|
(uint32_t *) &c, 1, NULL,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue