Skip to content

Commit 12bedb0

Browse files
committed
Core: Internal: Base32: m refactor
1 parent 57137ad commit 12bedb0

File tree

1 file changed

+3
-3
lines changed
  • hnix-store-core/src/System/Nix/Internal

1 file changed

+3
-3
lines changed

hnix-store-core/src/System/Nix/Internal/Base32.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ digits32 = Vector.fromList "0123456789abcdfghijklmnpqrsvwxyz"
2222

2323
-- | Encode a 'BS.ByteString' in Nix's base32 encoding
2424
encode :: ByteString -> Text
25-
encode c = Data.Text.pack $ fmap char32 [nChar - 1, nChar - 2 .. 0]
25+
encode c = Data.Text.pack $ takeCharPosFromDict <$> [nChar - 1, nChar - 2 .. 0]
2626
where
2727
-- Each base32 character gives us 5 bits of information, while
2828
-- each byte gives is 8. Because 'div' rounds down, we need to add
@@ -43,8 +43,8 @@ encode c = Data.Text.pack $ fmap char32 [nChar - 1, nChar - 2 .. 0]
4343
[ fromIntegral (byte j) * (256 ^ j)
4444
| j <- [0 .. Bytes.length c - 1] ]
4545

46-
char32 :: Integer -> Char
47-
char32 i = digits32 Vector.! digitInd
46+
takeCharPosFromDict :: Integer -> Char
47+
takeCharPosFromDict i = digits32 Vector.! digitInd
4848
where
4949
digitInd =
5050
fromIntegral $

0 commit comments

Comments
 (0)