File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
library/src/scala/collection/immutable Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import mutable.Builder
18
18
import scala .util .matching .Regex
19
19
import scala .math .ScalaNumber
20
20
import scala .reflect .ClassTag
21
+ import java .lang .{StringBuilder => JStringBuilder }
21
22
22
23
/** A companion object for the `StringLike` containing some constants.
23
24
* @since 2.8
@@ -69,10 +70,15 @@ self =>
69
70
70
71
/** Return the current string concatenated `n` times.
71
72
*/
72
- def * (n : Int ): String = {
73
- val buf = new StringBuilder
74
- for (i <- 0 until n) buf append toString
75
- buf.toString
73
+ def * (n : Int ): String = {
74
+ val s0 = toString
75
+ var ci = 0 max n
76
+ val sb = new JStringBuilder (s0.length * ci)
77
+ while (ci > 0 ) {
78
+ sb.append(s0)
79
+ ci -= 1
80
+ }
81
+ sb.toString
76
82
}
77
83
78
84
override def compare (other : String ) = toString compareTo other
You can’t perform that action at this time.
0 commit comments