aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Anvin <hpa@tazenda.(none)>2005-12-09 10:23:17 -0800
committerPeter Anvin <hpa@tazenda.(none)>2005-12-09 10:23:17 -0800
commit6a9b8df10fbdb198f2840b6d151130a5d30af3d0 (patch)
tree3e7c8678e03ececb6f39c2c93aac60614cef1b24
parent9f91b369501821ea04aff9695be2ce799329c800 (diff)
downloadlibucd-6a9b8df10fbdb198f2840b6d151130a5d30af3d0.tar.gz
No need to test for valid ucs in two places; invalid ucs is exceptional.
-rw-r--r--cache.c2
-rw-r--r--compiler.h4
-rw-r--r--ucslookup.c8
3 files changed, 7 insertions, 7 deletions
diff --git a/cache.c b/cache.c
index c96b67b..a617ffe 100644
--- a/cache.c
+++ b/cache.c
@@ -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;
}
diff --git a/compiler.h b/compiler.h
index a975a83..63181db 100644
--- a/compiler.h
+++ b/compiler.h
@@ -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 ) {