mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 13:37:57 +03:00
Merge pull request #606 from hellerve/better-repeat
Reduce allocations in String.repeat
This commit is contained in:
commit
c90d11b7ca
@ -29,10 +29,11 @@
|
||||
|
||||
(doc repeat "Returns a new string which is `inpt` repeated `n` times.")
|
||||
(defn repeat [n inpt]
|
||||
(let [str @""]
|
||||
(let [l (length inpt)
|
||||
str (String.allocate (* n l) \0)]
|
||||
(do
|
||||
(for [i 0 n]
|
||||
(set! str (append &str inpt)))
|
||||
(string-set-at! &str (* i l) inpt))
|
||||
str)))
|
||||
|
||||
(doc pad-left "Pads the left of a string with len bytes using the padding pad.")
|
||||
|
@ -91,11 +91,11 @@
|
||||
(if (Int.> (Int.+ passed failed) 0)
|
||||
(do
|
||||
(IO.color (Green))
|
||||
(if (Int.> passed 0) (IO.print &(String.append "\t|" &(String.repeat passed "="))) ())
|
||||
(if (Int.= failed 0) (IO.print "|") ())
|
||||
(when (Int.> passed 0) (IO.print &(String.append "\t|" &(String.allocate passed \=))))
|
||||
(when (Int.= failed 0) (IO.print "|"))
|
||||
(IO.color (Red))
|
||||
(if (Int.= passed 0) (IO.print "\t|") ())
|
||||
(if (Int.> failed 0) (IO.print &(String.append &(String.repeat failed "=") "|")) ())
|
||||
(when (Int.= passed 0) (IO.print "\t|"))
|
||||
(when (Int.> failed 0) (IO.print &(String.append &(String.allocate failed \=) "|")))
|
||||
(IO.println ""))
|
||||
())
|
||||
(IO.color (Green))
|
||||
|
Loading…
Reference in New Issue
Block a user