diff options
author | Peter Anvin <hpa@tazenda.(none)> | 2005-12-09 10:23:17 -0800 |
---|---|---|
committer | Peter Anvin <hpa@tazenda.(none)> | 2005-12-09 10:23:17 -0800 |
commit | 6a9b8df10fbdb198f2840b6d151130a5d30af3d0 (patch) | |
tree | 3e7c8678e03ececb6f39c2c93aac60614cef1b24 | |
parent | 9f91b369501821ea04aff9695be2ce799329c800 (diff) | |
download | libucd-6a9b8df10fbdb198f2840b6d151130a5d30af3d0.tar.gz |
No need to test for valid ucs in two places; invalid ucs is exceptional.
-rw-r--r-- | cache.c | 2 | ||||
-rw-r--r-- | compiler.h | 4 | ||||
-rw-r--r-- | ucslookup.c | 8 |
3 files changed, 7 insertions, 7 deletions
@@ -102,7 +102,7 @@ unicode_character_data(int32_t ucs) const struct unicode_character_data *ucd; struct cache_row *row; - if ( (uint32_t)ucs > UCS_MAX ) { + if ( unlikely((uint32_t)ucs > UCS_MAX) ) { errno = EINVAL; return NULL; } @@ -5,11 +5,15 @@ #define ALIGNED(x) __attribute__((aligned(x))) #define noreturn void __attribute__((noreturn)) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) #else #define ALIGNED(x) #define noreturn void +#define likely(x) (!!(x)) +#define unlikely(x) (!!(x)) #endif diff --git a/ucslookup.c b/ucslookup.c index 973d78a..bde1c0a 100644 --- a/ucslookup.c +++ b/ucslookup.c @@ -160,7 +160,8 @@ alloc_copy_properties(const struct _libucd_property_array *prop, } /* - * Actual data-generating function + * Actual data-generating function. ucs is required to be + * in the valid range [0..UCS_MAX]. */ const struct unicode_character_data * _libucd_character_data_raw(int32_t ucs) @@ -171,11 +172,6 @@ _libucd_character_data_raw(int32_t ucs) size_t namelen; struct unicode_character_data *ucd; - if ( (uint32_t)ucs > UCS_MAX ) { - errno = EINVAL; - return NULL; /* Invalid UCS value */ - } - hash = _libucd_ucstoname_hash(ucs); if ( hash >= PHASHNKEYS ) { |