@@ -231,47 +231,41 @@ intToAscii n =
231231 S.pack [toByte n]
232232
233233 else
234− intToAsciiHelp (numStartBytes * numInnerBytes) allBadFields (n - 53)
234+ intToAsciiHelp 2 (numStartBytes * numInnerBytes) allBadFields (n - 53)
235235
236236
237−intToAsciiHelp :: Int -> [BadFields] -> Int -> S.ShortByteString
238−intToAsciiHelp blockSize badFields n =
237+intToAsciiHelp :: Int -> Int -> [BadFields] -> Int -> S.ShortByteString
238+intToAsciiHelp width blockSize badFields n =
239239 case badFields of
240240 [] ->
241241 if n < blockSize then
242− unsafeIntToAscii n
242+ unsafeIntToAscii width [] n
243243 else
244− intToAsciiHelp (blockSize * numInnerBytes) [] (n - blockSize)
244+ intToAsciiHelp (width + 1) (blockSize * numInnerBytes) [] (n - blockSize)
245245
246246 BadFields renamings : biggerBadFields ->
247247 let availableSize = blockSize - Map.size renamings in
248248 if n < availableSize then
249− let name = unsafeIntToAscii n in
249+ let name = unsafeIntToAscii width [] n in
250250 Map.findWithDefault name name renamings
251251 else
252− intToAsciiHelp (blockSize * numInnerBytes) biggerBadFields (n - availableSize)
252+ intToAsciiHelp (width + 1) (blockSize * numInnerBytes) biggerBadFields (n - availableSize)
253253
254254
255255
256256-- UNSAFE INT TO ASCII
257257
258258
259−unsafeIntToAscii :: Int -> S.ShortByteString
260−unsafeIntToAscii n =
261− let
262− (quotient, remainder) =
263− quotRem n numStartBytes
264− in
265− S.pack $ toByte remainder : unsafeIntToAsciiHelp quotient
266−
267−
268−unsafeIntToAsciiHelp :: Int -> [Word8]
269−unsafeIntToAsciiHelp n =
270− if n == 0 then
271− []
259+unsafeIntToAscii :: Int -> [Word8] -> Int -> S.ShortByteString
260+unsafeIntToAscii width bytes n =
261+ if width <= 1 then
262+ S.pack (toByte n : bytes)
272263 else
273− let (quotient, remainder) = quotRem n numInnerBytes in
274− toByte remainder : unsafeIntToAsciiHelp quotient
264+ let
265+ (quotient, remainder) =
266+ quotRem n numInnerBytes
267+ in
268+ unsafeIntToAscii (width - 1) (toByte remainder : bytes) quotient
275269
276270
277271
@@ -322,12 +316,12 @@ allBadFields =
322316addRenaming :: N.Name -> Maybe BadFields -> BadFields
323317addRenaming keyword maybeBadFields =
324318 let
325− maxName =
326− numStartBytes * numInnerBytes ^ (N.length keyword - 1) - 1
319+ width = N.length keyword
320+ maxName = numStartBytes * numInnerBytes ^ (width - 1) - 1
327321 in
328322 case maybeBadFields of
329323 Nothing ->
330− BadFields $ Map.singleton (N.toShort keyword) (unsafeIntToAscii maxName)
324+ BadFields $ Map.singleton (N.toShort keyword) (unsafeIntToAscii width [] maxName)
331325
332326 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