From 89ddb85637cfc5be067fbb127c4b800e067ca243 Mon Sep 17 00:00:00 2001 From: Matthew Barr Date: Mon, 25 Jul 2016 16:06:37 +1000 Subject: [PATCH] Remove enum typedef --- src/fdr/fdr_streaming_compile.cpp | 10 +++++----- src/fdr/fdr_streaming_internal.h | 18 +++++++++--------- src/fdr/fdr_streaming_runtime.h | 13 +++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/fdr/fdr_streaming_compile.cpp b/src/fdr/fdr_streaming_compile.cpp index f84e3ad6..b2e1656c 100644 --- a/src/fdr/fdr_streaming_compile.cpp +++ b/src/fdr/fdr_streaming_compile.cpp @@ -147,7 +147,7 @@ void analyzeLits(const vector &long_lits, size_t max_len, } 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++) { hashedPositions[m]++; } @@ -162,7 +162,7 @@ void analyzeLits(const vector &long_lits, size_t max_len, #ifdef DEBUG_COMPILE 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 " "hashEntries %d\n", (m == CASEFUL) ? "caseful" : "caseless", boundaries[m], @@ -173,7 +173,7 @@ void analyzeLits(const vector &long_lits, size_t max_len, } 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); } @@ -195,7 +195,7 @@ struct OffsetIDFromEndOrder { static void fillHashes(const vector &long_lits, size_t max_len, - FDRSHashEntry *tab, size_t numEntries, MODES mode, + FDRSHashEntry *tab, size_t numEntries, Modes mode, map &litToOffsetVal) { const u32 nbits = lg2(numEntries); map > > bucketToLitOffPairs; @@ -412,7 +412,7 @@ fdrBuildTableStreaming(const vector &lits, ptr = secondaryTable.get() + htOffset[CASEFUL]; for (u32 m = CASEFUL; m < MAX_MODES; ++m) { fillHashes(long_lits, max_len, (FDRSHashEntry *)ptr, hashEntries[m], - (MODES)m, litToOffsetVal); + (Modes)m, litToOffsetVal); ptr += htSize[m]; } diff --git a/src/fdr/fdr_streaming_internal.h b/src/fdr/fdr_streaming_internal.h index 26602ce1..11b07b56 100644 --- a/src/fdr/fdr_streaming_internal.h +++ b/src/fdr/fdr_streaming_internal.h @@ -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 * modification, are permitted provided that the following conditions are met: @@ -41,11 +41,11 @@ // hash table (caseful) (FDRSHashEntry) // hash table (caseless) (FDRSHashEntry) -typedef enum { +enum Modes { CASEFUL = 0, CASELESS = 1, MAX_MODES = 2 -} MODES; +}; // We have one of these structures hanging off the 'link' of our secondary // FDR table that handles streaming strings @@ -91,12 +91,12 @@ struct FDRSHashEntry { }; 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]; } 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]; } @@ -107,17 +107,17 @@ const struct FDRSLiteral * getLitTab(const struct FDRSTableHeader * h) { } 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; } 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; } 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; } @@ -127,7 +127,7 @@ u32 has_bit(const struct FDRSHashEntry * ent, u32 bit) { } 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 MULTIPLIER = 0x0b4e0ef37bc32127ULL; assert(len >= 32); diff --git a/src/fdr/fdr_streaming_runtime.h b/src/fdr/fdr_streaming_runtime.h index fa5843c5..8e264c76 100644 --- a/src/fdr/fdr_streaming_runtime.h +++ b/src/fdr/fdr_streaming_runtime.h @@ -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 static really_inline u32 findLitTabEntry(const struct FDRSTableHeader * streamingTable, - u32 stateValue, MODES m) { + u32 stateValue, enum Modes m) { const struct FDRSLiteral * litTab = getLitTab(streamingTable); u32 lo = get_start_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 FDRSLiteral * litTab, const u32 *state_table, - const MODES m) { + const enum Modes m) { if (!state_table[m]) { return; } @@ -213,8 +213,9 @@ void fdrUnpackState(const struct FDR * fdr, struct FDR_Runtime_Args * a, } static really_inline -u32 do_single_confirm(const struct FDRSTableHeader * streamingTable, - const struct FDR_Runtime_Args * a, u32 hashState, MODES m) { +u32 do_single_confirm(const struct FDRSTableHeader *streamingTable, + const struct FDR_Runtime_Args *a, u32 hashState, + enum Modes m) { const struct FDRSLiteral * litTab = getLitTab(streamingTable); u32 idx = findLitTabEntry(streamingTable, hashState, m); size_t found_offset = litTab[idx].offset; @@ -279,7 +280,7 @@ void fdrFindStreamingHash(const struct FDR_Runtime_Args *a, static really_inline const struct FDRSHashEntry *getEnt(const struct FDRSTableHeader *streamingTable, - u32 h, const MODES m) { + u32 h, const enum Modes m) { u32 nbits = streamingTable->hashNBits[m]; if (!nbits) { return NULL; @@ -303,7 +304,7 @@ const struct FDRSHashEntry *getEnt(const struct FDRSTableHeader *streamingTable, static really_inline void fdrPackStateMode(u32 *state_table, const struct FDR_Runtime_Args *a, const struct FDRSTableHeader *streamingTable, - const struct FDRSHashEntry *ent, const MODES m) { + const struct FDRSHashEntry *ent, const enum Modes m) { assert(ent); assert(streamingTable->hashNBits[m]);