Unverified Commit 6d8c2227 authored by Silvan Mosberger's avatar Silvan Mosberger Committed by GitHub
Browse files

Merge pull request #273470 from adisbladis/lib-tohexstring-static-values

lib.toHexString: Statically compute hexDigits attrset
parents 5812c533 ad647985
Loading
Loading
Loading
Loading
+14 −16
Original line number Diff line number Diff line
@@ -520,22 +520,20 @@ in {

     toHexString 250 => "FA"
  */
  toHexString = i:
    let
      toHexDigit = d:
        if d < 10
        then toString d
        else
          {
  toHexString = let
    hexDigits = {
      "10" = "A";
      "11" = "B";
      "12" = "C";
      "13" = "D";
      "14" = "E";
      "15" = "F";
          }.${toString d};
    in
      lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
    };
    toHexDigit = d:
      if d < 10
      then toString d
      else hexDigits.${toString d};
  in i: lib.concatMapStrings toHexDigit (toBaseDigits 16 i);

  /* `toBaseDigits base i` converts the positive integer i to a list of its
     digits in the given base. For example: