Remove enum typedef

This commit is contained in:
Matthew Barr 2016-07-25 16:06:37 +10:00
parent cbd115f7fe
commit 89ddb85637
3 changed files with 21 additions and 20 deletions

View File

@ -147,7 +147,7 @@ void analyzeLits(const vector<hwlmLiteral> &long_lits, size_t max_len,
} }
for (const auto &lit : long_lits) { for (const auto &lit : long_lits) {
MODES m = lit.nocase ? CASELESS : CASEFUL; Modes m = lit.nocase ? CASELESS : CASEFUL;
for (u32 j = 1; j < lit.s.size() - max_len + 1; j++) { for (u32 j = 1; j < lit.s.size() - max_len + 1; j++) {
hashedPositions[m]++; hashedPositions[m]++;
} }
@ -162,7 +162,7 @@ void analyzeLits(const vector<hwlmLiteral> &long_lits, size_t max_len,
#ifdef DEBUG_COMPILE #ifdef DEBUG_COMPILE
printf("analyzeLits:\n"); printf("analyzeLits:\n");
for (MODES m = CASEFUL; m < MAX_MODES; m++) { for (Modes m = CASEFUL; m < MAX_MODES; m++) {
printf("mode %s boundary %d positions %d hashedPositions %d " printf("mode %s boundary %d positions %d hashedPositions %d "
"hashEntries %d\n", "hashEntries %d\n",
(m == CASEFUL) ? "caseful" : "caseless", boundaries[m], (m == CASEFUL) ? "caseful" : "caseless", boundaries[m],
@ -173,7 +173,7 @@ void analyzeLits(const vector<hwlmLiteral> &long_lits, size_t max_len,
} }
static static
u32 hashLit(const hwlmLiteral &l, u32 offset, size_t max_len, MODES m) { u32 hashLit(const hwlmLiteral &l, u32 offset, size_t max_len, Modes m) {
return streaming_hash((const u8 *)l.s.c_str() + offset, max_len, m); return streaming_hash((const u8 *)l.s.c_str() + offset, max_len, m);
} }
@ -195,7 +195,7 @@ struct OffsetIDFromEndOrder {
static static
void fillHashes(const vector<hwlmLiteral> &long_lits, size_t max_len, void fillHashes(const vector<hwlmLiteral> &long_lits, size_t max_len,
FDRSHashEntry *tab, size_t numEntries, MODES mode, FDRSHashEntry *tab, size_t numEntries, Modes mode,
map<u32, u32> &litToOffsetVal) { map<u32, u32> &litToOffsetVal) {
const u32 nbits = lg2(numEntries); const u32 nbits = lg2(numEntries);
map<u32, deque<pair<u32, u32> > > bucketToLitOffPairs; map<u32, deque<pair<u32, u32> > > bucketToLitOffPairs;
@ -412,7 +412,7 @@ fdrBuildTableStreaming(const vector<hwlmLiteral> &lits,
ptr = secondaryTable.get() + htOffset[CASEFUL]; ptr = secondaryTable.get() + htOffset[CASEFUL];
for (u32 m = CASEFUL; m < MAX_MODES; ++m) { for (u32 m = CASEFUL; m < MAX_MODES; ++m) {
fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m], fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m],
(MODES)m, litToOffsetVal); (Modes)m, litToOffsetVal);
ptr += htSize[m]; ptr += htSize[m];
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Intel Corporation * Copyright (c) 2015-2016, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -41,11 +41,11 @@
// hash table (caseful) (FDRSHashEntry) // hash table (caseful) (FDRSHashEntry)
// hash table (caseless) (FDRSHashEntry) // hash table (caseless) (FDRSHashEntry)
typedef enum { enum Modes {
CASEFUL = 0, CASEFUL = 0,
CASELESS = 1, CASELESS = 1,
MAX_MODES = 2 MAX_MODES = 2
} MODES; };
// We have one of these structures hanging off the 'link' of our secondary // We have one of these structures hanging off the 'link' of our secondary
// FDR table that handles streaming strings // FDR table that handles streaming strings
@ -91,12 +91,12 @@ struct FDRSHashEntry {
}; };
static really_inline static really_inline
u32 get_start_lit_idx(const struct FDRSTableHeader * h, MODES m) { u32 get_start_lit_idx(const struct FDRSTableHeader * h, enum Modes m) {
return m == CASEFUL ? 0 : h->boundary[m-1]; return m == CASEFUL ? 0 : h->boundary[m-1];
} }
static really_inline static really_inline
u32 get_end_lit_idx(const struct FDRSTableHeader * h, MODES m) { u32 get_end_lit_idx(const struct FDRSTableHeader * h, enum Modes m) {
return h->boundary[m]; return h->boundary[m];
} }
@ -107,17 +107,17 @@ const struct FDRSLiteral * getLitTab(const struct FDRSTableHeader * h) {
} }
static really_inline static really_inline
u32 getBaseOffsetOfLits(const struct FDRSTableHeader * h, MODES m) { u32 getBaseOffsetOfLits(const struct FDRSTableHeader * h, enum Modes m) {
return getLitTab(h)[get_start_lit_idx(h, m)].offset; return getLitTab(h)[get_start_lit_idx(h, m)].offset;
} }
static really_inline static really_inline
u32 packStateVal(const struct FDRSTableHeader * h, MODES m, u32 v) { u32 packStateVal(const struct FDRSTableHeader * h, enum Modes m, u32 v) {
return v - getBaseOffsetOfLits(h, m) + 1; return v - getBaseOffsetOfLits(h, m) + 1;
} }
static really_inline static really_inline
u32 unpackStateVal(const struct FDRSTableHeader * h, MODES m, u32 v) { u32 unpackStateVal(const struct FDRSTableHeader * h, enum Modes m, u32 v) {
return v + getBaseOffsetOfLits(h, m) - 1; return v + getBaseOffsetOfLits(h, m) - 1;
} }
@ -127,7 +127,7 @@ u32 has_bit(const struct FDRSHashEntry * ent, u32 bit) {
} }
static really_inline static really_inline
u32 streaming_hash(const u8 *ptr, UNUSED size_t len, MODES mode) { u32 streaming_hash(const u8 *ptr, UNUSED size_t len, enum Modes mode) {
const u64a CASEMASK = 0xdfdfdfdfdfdfdfdfULL; const u64a CASEMASK = 0xdfdfdfdfdfdfdfdfULL;
const u64a MULTIPLIER = 0x0b4e0ef37bc32127ULL; const u64a MULTIPLIER = 0x0b4e0ef37bc32127ULL;
assert(len >= 32); assert(len >= 32);

View File

@ -143,7 +143,7 @@ u32 fdrStreamStateActive(const struct FDR * fdr, const u8 * stream_state) {
// binary search for the literal index that contains the current state // binary search for the literal index that contains the current state
static really_inline static really_inline
u32 findLitTabEntry(const struct FDRSTableHeader * streamingTable, u32 findLitTabEntry(const struct FDRSTableHeader * streamingTable,
u32 stateValue, MODES m) { u32 stateValue, enum Modes m) {
const struct FDRSLiteral * litTab = getLitTab(streamingTable); const struct FDRSLiteral * litTab = getLitTab(streamingTable);
u32 lo = get_start_lit_idx(streamingTable, m); u32 lo = get_start_lit_idx(streamingTable, m);
u32 hi = get_end_lit_idx(streamingTable, m); u32 hi = get_end_lit_idx(streamingTable, m);
@ -175,7 +175,7 @@ void fdrUnpackStateMode(struct FDR_Runtime_Args *a,
const struct FDRSTableHeader *streamingTable, const struct FDRSTableHeader *streamingTable,
const struct FDRSLiteral * litTab, const struct FDRSLiteral * litTab,
const u32 *state_table, const u32 *state_table,
const MODES m) { const enum Modes m) {
if (!state_table[m]) { if (!state_table[m]) {
return; return;
} }
@ -213,8 +213,9 @@ void fdrUnpackState(const struct FDR * fdr, struct FDR_Runtime_Args * a,
} }
static really_inline static really_inline
u32 do_single_confirm(const struct FDRSTableHeader * streamingTable, u32 do_single_confirm(const struct FDRSTableHeader *streamingTable,
const struct FDR_Runtime_Args * a, u32 hashState, MODES m) { const struct FDR_Runtime_Args *a, u32 hashState,
enum Modes m) {
const struct FDRSLiteral * litTab = getLitTab(streamingTable); const struct FDRSLiteral * litTab = getLitTab(streamingTable);
u32 idx = findLitTabEntry(streamingTable, hashState, m); u32 idx = findLitTabEntry(streamingTable, hashState, m);
size_t found_offset = litTab[idx].offset; size_t found_offset = litTab[idx].offset;
@ -279,7 +280,7 @@ void fdrFindStreamingHash(const struct FDR_Runtime_Args *a,
static really_inline static really_inline
const struct FDRSHashEntry *getEnt(const struct FDRSTableHeader *streamingTable, const struct FDRSHashEntry *getEnt(const struct FDRSTableHeader *streamingTable,
u32 h, const MODES m) { u32 h, const enum Modes m) {
u32 nbits = streamingTable->hashNBits[m]; u32 nbits = streamingTable->hashNBits[m];
if (!nbits) { if (!nbits) {
return NULL; return NULL;
@ -303,7 +304,7 @@ const struct FDRSHashEntry *getEnt(const struct FDRSTableHeader *streamingTable,
static really_inline static really_inline
void fdrPackStateMode(u32 *state_table, const struct FDR_Runtime_Args *a, void fdrPackStateMode(u32 *state_table, const struct FDR_Runtime_Args *a,
const struct FDRSTableHeader *streamingTable, const struct FDRSTableHeader *streamingTable,
const struct FDRSHashEntry *ent, const MODES m) { const struct FDRSHashEntry *ent, const enum Modes m) {
assert(ent); assert(ent);
assert(streamingTable->hashNBits[m]); assert(streamingTable->hashNBits[m]);