How would you make this switch statement as fast as possible?

后端 未结 21 2036
别那么骄傲
别那么骄傲 2021-01-30 04:17

2009-12-04 UPDATE: For profiling results on a number of the suggestions posted here, see below!


The Question

Consider the following very

21条回答
  •  再見小時候
    2021-01-30 05:01

    Forgive me if I get something wrong here, I'm extrapolating from my knowledge of C++. For example, if you take ActivCode[0] of an empty string, in C++ you get a character whose value is zero.

    Create a two dimensional array which you initialize once; the first dimension is the length of the code, the second is a character value. Populate with the enumeration value you'd like to return. Now your entire function becomes:

    public static MarketDataExchange GetMarketDataExchange(string ActivCode) {
        return LookupTable[ActivCode.Length][ActivCode[0]];
    }
    

    Lucky for you all the two-character codes are unique in the first letter compared to the other two-character codes.

提交回复
热议问题