File tree 1 file changed +18
-19
lines changed
1 file changed +18
-19
lines changed Original file line number Diff line number Diff line change @@ -64,29 +64,28 @@ pub fn String::concat(
64
64
strings : Array [String ],
65
65
separator ~ : String = ""
66
66
) -> String {
67
- if strings .length () == 0 {
68
- ""
69
- } else {
70
- let hd = strings [0 ]
71
- let tl = strings [1 :]
72
- let mut size_hint = hd .length ()
73
- for s in tl {
74
- size_hint + = s .length () + separator .length ()
75
- }
76
- size_hint = size_hint << 1
77
- let buf = StringBuilder ::new (size_hint ~)
78
- buf .write_string (hd )
79
- if separator == "" {
67
+ match strings {
68
+ [] => ""
69
+ [hd , .. tl ] => {
70
+ let mut size_hint = hd .length ()
80
71
for s in tl {
81
- buf . write_string ( s )
72
+ size_hint + = s . length () + separator . length ( )
82
73
}
83
- } else {
84
- for s in tl {
85
- buf .write_string (separator )
86
- buf .write_string (s )
74
+ size_hint = size_hint << 1
75
+ let buf = StringBuilder ::new (size_hint ~)
76
+ buf .write_string (hd )
77
+ if separator == "" {
78
+ for s in tl {
79
+ buf .write_string (s )
80
+ }
81
+ } else {
82
+ for s in tl {
83
+ buf .write_string (separator )
84
+ buf .write_string (s )
85
+ }
87
86
}
87
+ buf .to_string ()
88
88
}
89
- buf .to_string ()
90
89
}
91
90
}
92
91
You can’t perform that action at this time.
0 commit comments