From ed29e1b0310185f1417daec8910e46aacfca687d Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 26 May 2026 13:38:47 -0400 Subject: [PATCH] lib.strings: remove throwIfNot usage throwIfNot sends our error message through a function call, even if the error condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- lib/strings.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index a926edfaeba6..59a458aecf80 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -1589,15 +1589,14 @@ rec { */ toSentenceCase = str: - lib.throwIfNot (isString str) - "toSentenceCase does only accepts string values, but got ${typeOf str}" - ( - let - firstChar = substring 0 1 str; - rest = substring 1 (-1) str; # -1 takes till the end of the string - in - toUpper firstChar + toLower rest - ); + if !isString str then + throw "toSentenceCase does only accepts string values, but got ${typeOf str}" + else + let + firstChar = substring 0 1 str; + rest = substring 1 (-1) str; # -1 takes till the end of the string + in + toUpper firstChar + toLower rest; /** Converts a string to camelCase. Handles snake_case, PascalCase, @@ -1633,7 +1632,9 @@ rec { */ toCamelCase = str: - lib.throwIfNot (isString str) "toCamelCase does only accepts string values, but got ${typeOf str}" ( + if !isString str then + throw "toCamelCase does only accepts string values, but got ${typeOf str}" + else let separators = splitStringBy ( prev: curr: @@ -1653,8 +1654,7 @@ rec { first = if length parts > 0 then toLower (head parts) else ""; rest = if length parts > 1 then map toSentenceCase (tail parts) else [ ]; in - concatStrings ([ first ] ++ rest) - ); + concatStrings ([ first ] ++ rest); /** Appends string context from string like object `src` to `target`.