Skip to content

Commit 2674604

Browse files
author
Tuan Hoang
committed
Improved performance of lsdevname app by using an unordered_map (aka hash map)
Signed-off-by: Tuan Hoang <[email protected]>
1 parent e69f164 commit 2674604

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

getkmoddevs/lsdevname.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <fstream>
1616
#include <iostream>
1717
#include <map>
18+
#include <unordered_map>
1819

1920
using namespace std;
2021

@@ -32,8 +33,8 @@ const string ONE_SPACE(" ");
3233
const string TWO_SPACES(" ");
3334

3435
// typedefs
35-
typedef map<string, string> vendors_map_t;
36-
typedef map<string, map<string, string>> devices_map_t;
36+
typedef unordered_map<string, string> vendors_map_t;
37+
typedef unordered_map<string, unordered_map<string, string>> devices_map_t;
3738

3839
// function prototypess
3940
void print_usage(char* progname);
@@ -77,8 +78,8 @@ int main(int argc, char** argv)
7778
return EXIT_FAILURE;
7879
}
7980

80-
map<string, string> vendors_map;
81-
map<string, map<string, string>> devices_map;
81+
vendors_map_t vendors_map;
82+
devices_map_t devices_map;
8283

8384
int print_all = 0;
8485
int print_numbers = 0;
@@ -270,7 +271,7 @@ void parse_ids(string const& ids_file, vendors_map_t& vendors_map, devices_map_t
270271
vendor_name = line.substr(line.find(TWO_SPACES) + TWO_SPACES.length());
271272

272273
vendors_map[vendor_id] = vendor_name;
273-
devices_map[vendor_id] = map<string, string>();
274+
devices_map[vendor_id] = unordered_map<string, string>();
274275
}
275276
}
276277
}

0 commit comments

Comments
 (0)