--- NumberFormatter.cs 2007-12-30 15:02:13.027134488 +0900 +++ NumberFormatter.reduce.cs 2007-12-31 09:42:27.605475016 +0900 @@ -74,32 +74,16 @@ // _decHexDigits s a translation table from a decimal number to its // digits hexadecimal representation (e.g. _decHexDigits [234] = 0x234). - static readonly int[] _decHexDigits = new int [10000]; - - // _decHexLen caches the number of digits in a hexadecimal number. - // For instance _decHexLen [0x234] = 3. - static readonly int[] _decHexLen = new int [0x10000]; + static readonly int[] _decHexDigits = new int [100]; static NumberFormatter () { - // Compute _decHexDigits and _decHexLen. + // Compute _decHexDigits. uint res = 0; for (int i = 0; i < _decHexDigits.Length; i++) { _decHexDigits [i] = (int)res; res = AddOneToDecHex (res); } - int len = 0; - for (int i = 0; i < _decHexLen.Length; i++) { - if (i == 0x1) - len = 1; - if (i == 0x10) - len = 2; - else if (i == 0x100) - len = 3; - else if (i == 0x1000) - len = 4; - _decHexLen [i] = len; - } } #endregion Static Fields @@ -210,23 +194,48 @@ private static uint ToDecHex (int val) { int res = 0; + if (val >= 1000000) { + int v = val / 1000000; + val -= v * 1000000; + res = _decHexDigits [v] << 24; + } if (val >= 10000) { int v = val / 10000; val -= v * 10000; - res = _decHexDigits [v] << 16; + res |= _decHexDigits [v] << 16; + } + if (val >= 100) { + int v = val / 100; + val -= v * 100; + res |= _decHexDigits [v] << 8; } return (uint)(res | _decHexDigits [val]); } // Helper to count number of hexadecimal digits in a number. - private static int DecHexLen (uint val) + private static int DecHexLen (uint v) { - int v = (int)val; - if (v < 0) - return 8; - if (v < 0x10000) - return _decHexLen [v]; - return 4 + _decHexLen [v >> 16]; + if (v < 0x10000) { + if (v < 0x100) { + if (v < 0x10) + return v == 0 ? 0 : 1; + return 2; + } else { + if (v < 0x1000) + return 3; + return 4; + } + } else { + if (v < 0x1000000) { + if (v < 0x100000) + return 5; + return 6; + } else { + if (v < 0x10000000) + return 7; + return 8; + } + } } // Count number of hexadecimal digits stored in _val1 .. _val4. @@ -1532,8 +1541,14 @@ Append ((char)('0' | exponent)); } else { - int hexDigit = _decHexDigits [exponent]; - if (exponent >= 100 || minDigits == 3) + int hexDigit = 0; + if (exponent >= 100) { + int v = exponent / 100; + exponent -= v * 100; + hexDigit = _decHexDigits [v] << 8; + } + hexDigit |= _decHexDigits [exponent]; + if ((hexDigit >> 8) != 0 || minDigits == 3) Append ((char)('0' | (hexDigit >> 8))); Append ((char)('0' | ((hexDigit >> 4) & 0xf))); Append ((char)('0' | (hexDigit & 0xf)));