Date:2015-04-22 19:42:47 (5 years 1 month ago)
Author:Maarten ter Huurne
Commit:9ca019ef513cdaaea64a283dd8f12c9c57787627
Message:Keep list of section names sorted at all times

Keeping it sorted when sections are inserted after startup improves the
user experience and if we have code for that already, we might as well
use it during startup too.
Files: src/menu.cpp (3 diffs)

Change Details

src/menu.cpp
7878    readSections(GMENU2X_SYSTEM_DIR "/sections");
7979    readSections(GMenu2X::getHome() + "/sections");
8080
81    sort(sections.begin(),sections.end(),case_less());
8281    setSectionIndex(0);
8382    readLinks();
8483
...... 
118117    if (!dirp) return;
119118
120119    while ((dptr = readdir(dirp))) {
121        if (dptr->d_name[0] == '.' || dptr->d_type != DT_DIR)
122            continue;
123
124        if (find(sections.begin(), sections.end(), dptr->d_name) == sections.end()) {
125            sections.emplace_back(dptr->d_name);
126            vector<Link*> ll;
127            links.push_back(ll);
120        if (dptr->d_name[0] != '.' && dptr->d_type == DT_DIR) {
121            // Create section if it doesn't exist yet.
122            sectionNamed(dptr->d_name);
128123        }
129124    }
130125
...... 
516511
517512int Menu::sectionNamed(const char *sectionName)
518513{
519    auto it = find(sections.begin(), sections.end(), sectionName);
514    auto it = lower_bound(sections.begin(), sections.end(), sectionName);
520515    int idx = it - sections.begin();
521    if (it == sections.end()) {
522        sections.emplace_back(sectionName);
523        links.emplace_back();
516    if (it == sections.end() || *it != sectionName) {
517        sections.emplace(it, sectionName);
518        links.emplace(links.begin() + idx);
524519    }
525520    return idx;
526521}

Archive Download the corresponding diff file



interactive