diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2016-08-27 10:13:20 +0200 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2016-08-27 10:13:20 +0200 |
commit | ae253286a5d31f1322844cc418c686c42b8e2f9a (patch) | |
tree | dbe91d740ca021d57782f45cb0b0f853283dba70 | |
parent | e110ddc88584292915449dc061e797b4dec5320d (diff) | |
parent | 86459c062692d24409cc382e9eeb97cf68462ad0 (diff) | |
download | sherlock.lv2-ae253286a5d31f1322844cc418c686c42b8e2f9a.tar.xz |
Merge commit '86459c062692d24409cc382e9eeb97cf68462ad0'
-rw-r--r-- | props.lv2/props.h | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/props.lv2/props.h b/props.lv2/props.h index 4ec4129..8f46d46 100644 --- a/props.lv2/props.h +++ b/props.lv2/props.h @@ -514,23 +514,16 @@ _type_qsort(props_type_t *a, unsigned n) static inline props_type_t * _type_bsearch(LV2_URID p, props_type_t *a, unsigned n) { - unsigned start = 0; - unsigned end = n; + props_type_t *base = a; - while(start < end) + for(unsigned N = n, half; N > 1; N -= half) { - const unsigned mid = start + (end - start)/2; - props_type_t *dst = &a[mid]; - - if(p < dst->urid) - end = mid; - else if(p > dst->urid) - start = mid + 1; - else - return dst; + half = N/2; + props_type_t *dst = &base[half]; + base = (dst->urid > p) ? base : dst; } - return NULL; + return (base->urid == p) ? base : NULL; } static inline void @@ -565,23 +558,16 @@ _impl_qsort(props_impl_t *a, unsigned n) static inline props_impl_t * _impl_bsearch(LV2_URID p, props_impl_t *a, unsigned n) { - unsigned start = 0; - unsigned end = n; + props_impl_t *base = a; - while(start < end) + for(unsigned N = n, half; N > 1; N -= half) { - const unsigned mid = start + (end - start)/2; - props_impl_t *dst = &a[mid]; - - if(p < dst->property) - end = mid; - else if(p > dst->property) - start = mid + 1; - else - return dst; + half = N/2; + props_impl_t *dst = &base[half]; + base = (dst->property > p) ? base : dst; } - return NULL; + return (base->property == p) ? base : NULL; } static inline props_impl_t * |