@@ -231,47 +231,41 @@ intToAscii n =
231 S.pack [toByte n]
231 S.pack [toByte n]
234− intToAsciiHelp (numStartBytes * numInnerBytes) allBadFields (n - 53)
234+ intToAsciiHelp 2 (numStartBytes * numInnerBytes) allBadFields (n - 53)
237−intToAsciiHelp :: Int -> [BadFields] -> Int -> S.ShortByteString
237+intToAsciiHelp :: Int -> Int -> [BadFields] -> Int -> S.ShortByteString
238−intToAsciiHelp blockSize badFields n =
238+intToAsciiHelp width blockSize badFields n =
239 case badFields of
239 case badFields of
241 if n < blockSize then
241 if n < blockSize then
242− unsafeIntToAscii n
242+ unsafeIntToAscii width [] n
244− intToAsciiHelp (blockSize * numInnerBytes) [] (n - blockSize)
244+ intToAsciiHelp (width + 1) (blockSize * numInnerBytes) [] (n - blockSize)
246 BadFields renamings : biggerBadFields ->
246 BadFields renamings : biggerBadFields ->
247 let availableSize = blockSize - Map.size renamings in
247 let availableSize = blockSize - Map.size renamings in
248 if n < availableSize then
248 if n < availableSize then
249− let name = unsafeIntToAscii n in
249+ let name = unsafeIntToAscii width [] n in
250 Map.findWithDefault name name renamings
250 Map.findWithDefault name name renamings
252− intToAsciiHelp (blockSize * numInnerBytes) biggerBadFields (n - availableSize)
252+ intToAsciiHelp (width + 1) (blockSize * numInnerBytes) biggerBadFields (n - availableSize)
256-- UNSAFE INT TO ASCII
256-- UNSAFE INT TO ASCII
259−unsafeIntToAscii :: Int -> S.ShortByteString
259+unsafeIntToAscii :: Int -> [Word8] -> Int -> S.ShortByteString
260−unsafeIntToAscii n =
260+unsafeIntToAscii width bytes n =
261− let
261+ if width <= 1 then
262− (quotient, remainder) =
262+ S.pack (toByte n : bytes)
263− quotRem n numStartBytes
265− S.pack $ toByte remainder : unsafeIntToAsciiHelp quotient
268−unsafeIntToAsciiHelp :: Int -> [Word8]
269−unsafeIntToAsciiHelp n =
265+ (quotient, remainder) =
273− let (quotient, remainder) = quotRem n numInnerBytes in
266+ quotRem n numInnerBytes
274− toByte remainder : unsafeIntToAsciiHelp quotient
268+ unsafeIntToAscii (width - 1) (toByte remainder : bytes) quotient
@@ -322,12 +316,12 @@ allBadFields =
322addRenaming :: N.Name -> Maybe BadFields -> BadFields
316addRenaming :: N.Name -> Maybe BadFields -> BadFields
323addRenaming keyword maybeBadFields =
317addRenaming keyword maybeBadFields =
325− maxName =
319+ width = N.length keyword
326− numStartBytes * numInnerBytes ^ (N.length keyword - 1) - 1
320+ maxName = numStartBytes * numInnerBytes ^ (width - 1) - 1
328 case maybeBadFields of
322 case maybeBadFields of
329 Nothing ->
323 Nothing ->
330− BadFields $ Map.singleton (N.toShort keyword) (unsafeIntToAscii maxName)
324+ BadFields $ Map.singleton (N.toShort keyword) (unsafeIntToAscii width [] maxName)
332 Just (BadFields renamings) ->
326 Just (BadFields renamings) ->
333− BadFields $ Map.insert (N.toShort keyword) (unsafeIntToAscii (maxName - Map.size renamings)) renamings
327+ BadFields $ Map.insert (N.toShort keyword) (unsafeIntToAscii width [] (maxName - Map.size renamings)) renamings