diff options
Diffstat (limited to 'iconv/skeleton.c')
-rw-r--r-- | iconv/skeleton.c | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/iconv/skeleton.c b/iconv/skeleton.c index 76189b56a9..f459ed588f 100644 --- a/iconv/skeleton.c +++ b/iconv/skeleton.c @@ -57,7 +57,12 @@ from the current characters. TO_LOOP likewise for the other direction - RESET_STATE in case of an error we must reset the state for + ONE_DIRECTION optional. If defined to 1, only one conversion + direction is defined instead of two. In this + case, FROM_DIRECTION should be defined to 1, and + FROM_LOOP and TO_LOOP should have the same value. + + SAVE_RESET_STATE in case of an error we must reset the state for the rerun so this macro must be defined for stateful encodings. It takes an argument which is nonzero when saving. @@ -184,8 +189,8 @@ static int to_object; #endif -/* For conversions from a fixed width character sets to another fixed width - character set we we can define RESET_INPUT_BUFFER is necessary. */ +/* For conversions from a fixed width character set to another fixed width + character set we can define RESET_INPUT_BUFFER in a very fast way. */ #if !defined RESET_INPUT_BUFFER && !defined SAVE_RESET_STATE # if MIN_NEEDED_FROM == MAX_NEEDED_FROM && MIN_NEEDED_TO == MAX_NEEDED_TO /* We have to use these `if's here since the compiler cannot know that @@ -233,7 +238,7 @@ gconv_init (struct __gconv_step *step) else return __GCONV_NOCONV; -#ifdef RESET_STATE +#ifdef SAVE_RESET_STATE step->__stateful = 1; #else step->__stateful = 0; @@ -245,8 +250,8 @@ gconv_init (struct __gconv_step *step) /* The default destructor function does nothing in the moment and so - be define it at all. But we still provide the macro just in case - we need it some day. */ + we don't define it at all. But we still provide the macro just in + case we need it some day. */ #if DEFINE_FINI #endif @@ -339,7 +344,8 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, /* If the function is used to implement the mb*towc*() or wc*tomb*() functions we must test whether any bytes from the last call are stored in the `state' object. */ - if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION) + if (((MAX_NEEDED_FROM > 1 && MAX_NEEDED_TO > 1) + || (MAX_NEEDED_FROM > 1 && FROM_DIRECTION) || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION)) && consume_incomplete && (data->__statep->__count & 7) != 0) { @@ -491,23 +497,44 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, SAVE_RESET_STATE (0); # endif - /* XXX Handle unaligned access here as well. */ - if (FROM_DIRECTION) - /* Run the conversion loop. */ - nstatus = FROM_LOOP (step, data, - (const unsigned char **) inptrp, - (const unsigned char *) inend, - (unsigned char **) &outbuf, - (unsigned char *) outerr, - lirreversiblep EXTRA_LOOP_ARGS); + if (__builtin_expect (!unaligned, 1)) + { + if (FROM_DIRECTION) + /* Run the conversion loop. */ + nstatus = FROM_LOOP (step, data, inptrp, inend, + &outbuf, + (unsigned char *) outerr, + lirreversiblep + EXTRA_LOOP_ARGS); + else + /* Run the conversion loop. */ + nstatus = TO_LOOP (step, data, inptrp, inend, + &outbuf, + (unsigned char *) outerr, + lirreversiblep + EXTRA_LOOP_ARGS); + } +# if !defined _STRING_ARCH_unaligned \ + && MIN_NEEDED_FROM != 1 && MAX_NEEDED_FROM % MIN_NEEDED_FROM == 0 \ + && MIN_NEEDED_TO != 1 && MAX_NEEDED_TO % MIN_NEEDED_TO == 0 else - /* Run the conversion loop. */ - nstatus = TO_LOOP (step, data, - (const unsigned char **) inptrp, - (const unsigned char *) inend, - (unsigned char **) &outbuf, - (unsigned char *) outerr, - lirreversiblep EXTRA_LOOP_ARGS); + { + if (FROM_DIRECTION) + /* Run the conversion loop. */ + nstatus = GEN_unaligned (FROM_LOOP) (step, data, + inptrp, inend, + (unsigned char *) outerr, + lirreversiblep + EXTRA_LOOP_ARGS); + else + /* Run the conversion loop. */ + nstatus = GEN_unaligned (TO_LOOP) (step, data, + inptrp, inend, + (unsigned char *) outerr, + lirreversiblep + EXTRA_LOOP_ARGS); + } +# endif /* We must run out of output buffer space in this rerun. */ @@ -540,7 +567,8 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, /* If we are supposed to consume all character store now all of the remaining characters in the `state' object. */ #if MAX_NEEDED_FROM > 1 || MAX_NEEDED_TO > 1 - if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION) + if (((MAX_NEEDED_FROM > 1 && MAX_NEEDED_TO > 1) + || (MAX_NEEDED_FROM > 1 && FROM_DIRECTION) || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION)) && __builtin_expect (consume_incomplete, 0) && status == __GCONV_INCOMPLETE_INPUT) @@ -580,7 +608,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, #undef EMIT_SHIFT_TO_INIT #undef FROM_LOOP #undef TO_LOOP -#undef RESET_STATE +#undef SAVE_RESET_STATE #undef RESET_INPUT_BUFFER #undef FUNCTION_NAME #undef PREPARE_LOOP |