dovecot-2.2: lib: API change - have uni_utf8_get_char*() return ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 1 19:19:08 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/8b7be28bd518
changeset: 18786:8b7be28bd518
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 01 22:08:43 2015 +0300
description:
lib: API change - have uni_utf8_get_char*() return _char_bytes
Often the two functions are called in close proximity (both ways round). As
_get_char*() calls _char_bytes() early on the success path, we may as well
return that value to the caller for immediate use.

The callers which call _char_bytes() first are simply rejecting the truncated
case quickly - all other invalid cases still call both functions, and all
other valid cases (which should be the fast path) likewise call both.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/unichar.c |  2 +-
 src/lib/unichar.h |  2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diffs (24 lines):

diff -r 7bd2f9be5493 -r 8b7be28bd518 src/lib/unichar.c
--- a/src/lib/unichar.c	Mon Jun 01 22:08:27 2015 +0300
+++ b/src/lib/unichar.c	Mon Jun 01 22:08:43 2015 +0300
@@ -79,7 +79,7 @@
 
 	if (len <= max_len) {
 		lowest_valid_chr = lowest_valid_chr_table[len];
-		ret = 1;
+		ret = len;
 	} else {
 		/* check first if the input is invalid before returning 0 */
 		lowest_valid_chr = 0;
diff -r 7bd2f9be5493 -r 8b7be28bd518 src/lib/unichar.h
--- a/src/lib/unichar.h	Mon Jun 01 22:08:27 2015 +0300
+++ b/src/lib/unichar.h	Mon Jun 01 22:08:43 2015 +0300
@@ -48,7 +48,7 @@
 void uni_ucs4_to_utf8(const unichar_t *input, size_t len, buffer_t *output);
 void uni_ucs4_to_utf8_c(unichar_t chr, buffer_t *output);
 
-/* Returns 1 if *chr_r is set, 0 for incomplete trailing character,
+/* Returns char_bytes (>0) if *chr_r is set, 0 for incomplete trailing character,
    -1 for invalid input. */
 int uni_utf8_get_char(const char *input, unichar_t *chr_r);
 int uni_utf8_get_char_n(const void *input, size_t max_len, unichar_t *chr_r);


More information about the dovecot-cvs mailing list