Skip to content

Commit 3d503c4

Browse files
authored
Refactor argument matching with case insensitive string comparison (#580)
1 parent fb01581 commit 3d503c4

2 files changed

Lines changed: 1 addition & 19 deletions

File tree

ddprof-lib/src/main/cpp/arguments.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,13 @@ static const Multiplier UNIVERSAL[] = {
4242
{'n', 1}, {'u', 1000}, {'m', 1000000}, {'s', 1000000000},
4343
{'b', 1}, {'k', 1024}, {'g', 1073741824}, {0, 0}};
4444

45-
// Statically compute hash code of a string containing up to 12 [a-z] letters
46-
#define HASH(s) \
47-
((s[0] & 31LL) | (s[1] & 31LL) << 5 | (s[2] & 31LL) << 10 | \
48-
(s[3] & 31LL) << 15 | (s[4] & 31LL) << 20 | (s[5] & 31LL) << 25 | \
49-
(s[6] & 31LL) << 30 | (s[7] & 31LL) << 35 | (s[8] & 31LL) << 40 | \
50-
(s[9] & 31LL) << 45 | (s[10] & 31LL) << 50 | (s[11] & 31LL) << 55)
51-
5245
// Simulate switch statement over string hashes
5346
#define SWITCH(arg) \
54-
long long arg_hash = hash(arg); \
5547
if (0)
5648

5749
#define CASE(s) \
5850
} \
59-
else if (arg_hash == HASH(s " ")) {
51+
else if (strcasecmp(arg, s) == 0) {
6052

6153
#define DEFAULT() \
6254
} \
@@ -437,15 +429,6 @@ const char *Arguments::file() {
437429
return _file;
438430
}
439431

440-
// Should match statically computed HASH(arg)
441-
long long Arguments::hash(const char *arg) {
442-
long long h = 0;
443-
for (int shift = 0; *arg != 0; shift += 5) {
444-
h |= (*arg++ & 31LL) << shift;
445-
}
446-
return h;
447-
}
448-
449432
// Expands the following patterns:
450433
// %p process id
451434
// %t timestamp (yyyyMMdd-hhmmss)

ddprof-lib/src/main/cpp/arguments.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class Arguments {
152152
bool _shared;
153153
bool _persistent;
154154
const char *expandFilePattern(const char *pattern);
155-
static long long hash(const char *arg);
156155
static long parseUnits(const char *str, const Multiplier *multipliers);
157156
static bool isCpuEvent(const char *event) {
158157
// event == NULL will default to EVENT_CPU

0 commit comments

Comments
 (0)