Commit c319edf54bd39e68b5dbb2d15f43aaa0aec61755
1 parent
23c33c57
remove the bsearch from interface selection. The amount of interfaces is very li…
…mited and there is no benefit compared to a direct iteration
Showing
2 changed files
with
11 additions
and
43 deletions
| ... | ... | @@ -88,7 +88,7 @@ |
| 88 | 88 | * \see TR_CREATE_CLASS |
| 89 | 89 | */ |
| 90 | 90 | #define TR_INIT_IFACE_IMPL(...) \ |
| 91 | - {TR_IFACE_NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} | |
| 91 | + {TR_IFACE_NUMARGS(__VA_ARGS__), {__VA_ARGS__}} | |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * The interface implementations for a class. |
| ... | ... | @@ -99,16 +99,6 @@ |
| 99 | 99 | struct TR_iface_impl { |
| 100 | 100 | /** the number of interface implementations */ |
| 101 | 101 | const size_t nimpl; |
| 102 | - /** | |
| 103 | - * This indicates if impls was sorted. The first time it | |
| 104 | - * will be accessed via TR_interfaceGet, This array will | |
| 105 | - * be sorted with quicksort to make subsequent interface | |
| 106 | - * searches faster. After it was sorted this flag will be set | |
| 107 | - * to true, | |
| 108 | - * | |
| 109 | - * \see TR_interfaceGet | |
| 110 | - */ | |
| 111 | - char simpl; | |
| 112 | 102 | /** Array to hold the used interface implementations. */ |
| 113 | 103 | const void * impl[TR_MAX_IFACE]; |
| 114 | 104 | }; | ... | ... |
| ... | ... | @@ -28,45 +28,23 @@ |
| 28 | 28 | #include "tr/commons.h" |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Compare interfaces. | |
| 32 | - * Used with bsearch on the interfaces. | |
| 33 | - */ | |
| 34 | -static | |
| 35 | -inline | |
| 36 | -int | |
| 37 | -comp(const void * _a, const void * _b) | |
| 38 | -{ | |
| 39 | - const struct interface * a = **(const struct interface ***)_a; | |
| 40 | - const struct interface * b = **(const struct interface ***)_b; | |
| 41 | - return ((a)<(b))? -1 : ((a)>(b))? 1 : 0; | |
| 42 | -} | |
| 43 | - | |
| 44 | -/** | |
| 45 | 31 | * Get a specific interface implementation from the interface |
| 46 | 32 | * implementation from a class. |
| 47 | 33 | */ |
| 48 | 34 | TR_iface_ptr |
| 49 | -TR_interfaceGet(TR_iface_impl_ptr iface_impl, const TR_iface_ptr _iface) | |
| 35 | +TR_interfaceGet(TR_iface_impl_ptr iface_impl, const TR_iface_ptr iface) | |
| 50 | 36 | { |
| 51 | - const TR_iface_ptr * iface = &_iface; | |
| 52 | - TR_iface_ptr * found; | |
| 53 | - | |
| 54 | - if (! iface_impl->simpl) { | |
| 55 | - qsort( | |
| 56 | - (void**)(iface_impl->impl), | |
| 57 | - iface_impl->nimpl, | |
| 58 | - sizeof(TR_iface_ptr), comp); | |
| 59 | - iface_impl->simpl=TRUE; | |
| 60 | - } | |
| 37 | + TR_iface_ptr found = (TR_iface_ptr)NULL; | |
| 38 | + size_t i; | |
| 61 | 39 | |
| 62 | - found = bsearch( | |
| 63 | - &iface, | |
| 64 | - iface_impl->impl, | |
| 65 | - iface_impl->nimpl, | |
| 66 | - sizeof(TR_iface_ptr), | |
| 67 | - comp); | |
| 40 | + for (i = 0; i < iface_impl->nimpl; i++) { | |
| 41 | + if (*(TR_iface_ptr *)(iface_impl->impl[i]) == iface) { | |
| 42 | + found = iface_impl->impl[i]; | |
| 43 | + break; | |
| 44 | + } | |
| 45 | + } | |
| 68 | 46 | |
| 69 | - return found? *found : (TR_iface_ptr)NULL; | |
| 47 | + return found; | |
| 70 | 48 | } |
| 71 | 49 | |
| 72 | 50 | // vim: set ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment