diff options
-rw-r--r-- | epan/pci-ids.c | 37 | ||||
-rwxr-xr-x | tools/make-pci-ids.py | 37 |
2 files changed, 10 insertions, 64 deletions
diff --git a/epan/pci-ids.c b/epan/pci-ids.c index f506c147de..04dda1b510 100644 --- a/epan/pci-ids.c +++ b/epan/pci-ids.c @@ -30,6 +30,7 @@ #include <config.h> #include <stddef.h> +#include <stdlib.h> #include "pci-ids.h" @@ -46525,38 +46526,10 @@ static pci_vid_index_t const pci_vid_index[] = { {0xFFFF, 1, pci_vid_FFFF }, }; /* We have 2376 VIDs */ -static pci_vid_index_t const *get_vid_index(uint16_t vid) +static int vid_search(const void *key, const void *tbl_entry) { - uint32_t start_index = 0; - uint32_t end_index = 0; - uint32_t idx = 0; - - end_index = sizeof(pci_vid_index)/sizeof(pci_vid_index[0]); - - while(start_index != end_index) - { - if(end_index - start_index == 1) - { - if(pci_vid_index[start_index].vid == vid) - return &pci_vid_index[start_index]; - - break; - } - - idx = (start_index + end_index)/2; - - if(pci_vid_index[idx].vid < vid) - start_index = idx; - else - if(pci_vid_index[idx].vid > vid) - end_index = idx; - else - return &pci_vid_index[idx]; - - } - - return NULL; - + return (int)*(const uint16_t *)key - + (int)((const pci_vid_index_t *)tbl_entry)->vid; } const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid) @@ -46566,7 +46539,7 @@ const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid) pci_vid_index_t const *index_ptr; pci_id_t const *ids_ptr; - index_ptr = get_vid_index(vid); + index_ptr = bsearch(&vid, pci_vid_index, sizeof pci_vid_index / sizeof pci_vid_index[0], sizeof pci_vid_index[0], vid_search); if(index_ptr == NULL) return not_found; diff --git a/tools/make-pci-ids.py b/tools/make-pci-ids.py index 093637d729..554fcb4d63 100755 --- a/tools/make-pci-ids.py +++ b/tools/make-pci-ids.py @@ -35,6 +35,7 @@ CODE_PREFIX = """\ #include <config.h> #include <stddef.h> +#include <stdlib.h> #include "pci-ids.h" @@ -59,38 +60,10 @@ typedef struct """ CODE_POSTFIX = """ -static pci_vid_index_t const *get_vid_index(uint16_t vid) +static int vid_search(const void *key, const void *tbl_entry) { - uint32_t start_index = 0; - uint32_t end_index = 0; - uint32_t idx = 0; - - end_index = sizeof(pci_vid_index)/sizeof(pci_vid_index[0]); - - while(start_index != end_index) - { - if(end_index - start_index == 1) - { - if(pci_vid_index[start_index].vid == vid) - return &pci_vid_index[start_index]; - - break; - } - - idx = (start_index + end_index)/2; - - if(pci_vid_index[idx].vid < vid) - start_index = idx; - else - if(pci_vid_index[idx].vid > vid) - end_index = idx; - else - return &pci_vid_index[idx]; - - } - - return NULL; - + return (int)*(const uint16_t *)key - + (int)((const pci_vid_index_t *)tbl_entry)->vid; } const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid) @@ -100,7 +73,7 @@ const char *pci_id_str(uint16_t vid, uint16_t did, uint16_t svid, uint16_t ssid) pci_vid_index_t const *index_ptr; pci_id_t const *ids_ptr; - index_ptr = get_vid_index(vid); + index_ptr = bsearch(&vid, pci_vid_index, sizeof pci_vid_index / sizeof pci_vid_index[0], sizeof pci_vid_index[0], vid_search); if(index_ptr == NULL) return not_found; |