Skip to content

Commit d2bde39

Browse files
v.cflags: use strings.Builder instead of concatenation for constructing flags (#17049)
1 parent 90dbf68 commit d2bde39

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

vlib/v/cflag/cflags.v

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
module cflag
55

66
import os
7+
import strings
78

89
// parsed cflag
910
pub struct CFlag {
@@ -24,7 +25,7 @@ const fexisting_literal = r'$first_existing'
2425

2526
// expand the flag value
2627
pub fn (cf &CFlag) eval() string {
27-
mut value := ''
28+
mut value_builder := strings.new_builder(10 * cf.value.len)
2829
cflag_eval_outer_loop: for i := 0; i < cf.value.len; i++ {
2930
x := cf.value[i]
3031
if x == `$` {
@@ -37,17 +38,17 @@ pub fn (cf &CFlag) eval() string {
3738
for spath in svalues {
3839
if os.exists(spath) {
3940
// found_spath = spath
40-
value += spath
41+
value_builder.write_string(spath)
4142
continue cflag_eval_outer_loop
4243
}
4344
}
4445
panic('>> error: none of the paths ${svalues} exist')
4546
continue
4647
}
4748
}
48-
value += x.ascii_str()
49+
value_builder.write_string(x.ascii_str())
4950
}
50-
return value
51+
return value_builder.str()
5152
}
5253

5354
// format flag
@@ -79,7 +80,7 @@ pub fn (cflags []CFlag) c_options_after_target_msvc() []string {
7980

8081
pub fn (cflags []CFlag) c_options_before_target() []string {
8182
defines, others, _ := cflags.defines_others_libs()
82-
mut args := []string{}
83+
mut args := []string{cap: defines.len + others.len}
8384
args << defines
8485
args << others
8586
return args

0 commit comments

Comments
 (0)