# HG changeset patch # User mas01cr # Date 1233755222 0 # Node ID ad561daf75ca2202d19ef2d4ec4d460d0dab66a3 # Parent 77e63d5c6de0f79964b4737c585dcea56696c0d8 Use upper_bound rather than lower_bound in audiodb_index_to_track_id() Saves us one explicit conditional. diff -r 77e63d5c6de0 -r ad561daf75ca audioDB-internals.h --- a/audioDB-internals.h Wed Feb 04 11:37:07 2009 +0000 +++ b/audioDB-internals.h Wed Feb 04 13:47:02 2009 +0000 @@ -271,15 +271,12 @@ return (*adb->keys)[index].c_str(); } -static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid){ - std::vector::iterator it_b = (*adb->track_offsets).begin(); - std::vector::iterator it_e = (*adb->track_offsets).end(); - off_t test_id = lshid*adb->header->dim*sizeof(double); - std::vector::iterator point_p = std::lower_bound(it_b, it_e, test_id); - if(*point_p == test_id) - return point_p - it_b; // lshid is first point in found track - else - return point_p - it_b - 1; // lshid is a point in the previous track +static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid) { + off_t offset = lshid * adb->header->dim * sizeof(double); + std::vector::iterator b = (*adb->track_offsets).begin(); + std::vector::iterator e = (*adb->track_offsets).end(); + std::vector::iterator p = std::upper_bound(b, e, offset); + return p - b - 1; } static inline uint32_t audiodb_index_to_track_pos(adb_t *adb, uint32_t track_id, uint32_t lshid) {