Commit bbd66b04 authored by Lev Walkin's avatar Lev Walkin

code made faster

parent e18ca715
...@@ -63,53 +63,35 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name, ...@@ -63,53 +63,35 @@ UTF8String_length(const UTF8String_t *st, const char *opt_type_name,
asn_app_consume_bytes_f *app_errlog, void *app_key) { asn_app_consume_bytes_f *app_errlog, void *app_key) {
if(st && st->buf) { if(st && st->buf) {
size_t length = 0; size_t length;
uint8_t *buf = st->buf; uint8_t *buf = st->buf;
uint8_t *end = buf + st->size; uint8_t *end = buf + st->size;
int want; /* Number of bytes wanted */
for(want = 0; buf < end; buf++) { for(length = 0; buf < end; length++) {
uint8_t ch = *buf; int ch = *buf;
int w = UTF8String_ht[0][ch >> 4]; int want = UTF8String_ht[0][ch >> 4];
if(want) { /* Continuation expected */ switch(want) {
if(w) { case -1: /* Second half of the table, long sequence */
want = UTF8String_ht[1][ch & 0x0F];
if(want != -1)
break; /* Fine value */
case 0: /* 10xxxxxx should not appear here */
_ASN_ERRLOG(app_errlog, app_key, _ASN_ERRLOG(app_errlog, app_key,
"%s: UTF-8 expectation " "%s: UTF-8 expectation failed "
"failed at byte %d (%s:%d)", "at byte %d (%s:%d)",
opt_type_name, opt_type_name,
(buf - st->buf) + 1, (buf - st->buf) + 1,
__FILE__, __LINE__); __FILE__, __LINE__);
return -1; return -1;
} }
want--; if(buf + want > end) {
} else {
switch(w) {
case -1: /* Long UTF-8 */
w = UTF8String_ht[1][ch & 0x0F];
if(w != -1)
break;
/* Fall through */
case 0: /* But we should want something! */
_ASN_ERRLOG(app_errlog, app_key,
"%s: UTF-8 expectation"
"failed at byte %d (%s:%d)",
opt_type_name,
(buf - st->buf) + 1,
__FILE__, __LINE__);
return -1;
}
want = w - 1; /* Expect this much */
}
if(!want) length++;
}
/* If still want something, then something is wrong */
if(want) {
_ASN_ERRLOG(app_errlog, app_key, _ASN_ERRLOG(app_errlog, app_key,
"%s: truncated UTF-8 sequence (%s:%d)", "%s: truncated UTF-8 sequence (%s:%d)",
opt_type_name, __FILE__, __LINE__); opt_type_name, __FILE__, __LINE__);
return -1; return -1;
} }
buf += want;
}
return length; return length;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment