From ebb98f3929360f3abb681dfca4caa8a190f9c5a8 Mon Sep 17 00:00:00 2001
From: Herbert Valerio Riedel <hvr@gnu.org>
Date: Sun, 23 Jun 2019 18:05:39 +0200
Subject: [PATCH] Tweak 888b9771c6064aa2ab98464f589d793e826f79ce

This avoids the shadowing warning and also reduces
integer overflowing corner cases.
---
 Data/Text.hs | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Data/Text.hs b/Data/Text.hs
index fa405034..dd1b821c 100644
--- a/Data/Text.hs
+++ b/Data/Text.hs
@@ -1107,15 +1107,15 @@ replicate n t@(Text a o l)
     | isSingleton t          = replicateChar n (unsafeHead t)
     | otherwise              = Text (A.run x) 0 len
   where
-    len = l `mul` n
+    len = l `mul` n -- TODO: detect overflows
     x :: ST s (A.MArray s)
     x = do
       arr <- A.new len
       A.copyI arr 0 a o l
-      let loop !l =
-            let l2 = l `shiftL` 1 in
-            if l2 > len then A.copyM arr l arr 0 (len - l) >> return arr
-            else A.copyM arr l arr 0 l >> loop l2
+      let loop !l1 =
+            let rest = len - l1 in
+            if rest <= l1 then A.copyM arr l1 arr 0 rest >> return arr
+            else A.copyM arr l1 arr 0 l1 >> loop (l1 `shiftL` 1)
       loop l
 {-# INLINE [1] replicate #-}
 
-- 
GitLab