1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.cflags: use strings.Builder instead of concatenation for constructing flags (#17049)

This commit is contained in:
MatejMagat305 2023-01-20 15:20:36 +01:00 committed by GitHub
parent 90dbf683d5
commit d2bde39347
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
module cflag module cflag
import os import os
import strings
// parsed cflag // parsed cflag
pub struct CFlag { pub struct CFlag {
@ -24,7 +25,7 @@ const fexisting_literal = r'$first_existing'
// expand the flag value // expand the flag value
pub fn (cf &CFlag) eval() string { pub fn (cf &CFlag) eval() string {
mut value := '' mut value_builder := strings.new_builder(10 * cf.value.len)
cflag_eval_outer_loop: for i := 0; i < cf.value.len; i++ { cflag_eval_outer_loop: for i := 0; i < cf.value.len; i++ {
x := cf.value[i] x := cf.value[i]
if x == `$` { if x == `$` {
@ -37,7 +38,7 @@ pub fn (cf &CFlag) eval() string {
for spath in svalues { for spath in svalues {
if os.exists(spath) { if os.exists(spath) {
// found_spath = spath // found_spath = spath
value += spath value_builder.write_string(spath)
continue cflag_eval_outer_loop continue cflag_eval_outer_loop
} }
} }
@ -45,9 +46,9 @@ pub fn (cf &CFlag) eval() string {
continue continue
} }
} }
value += x.ascii_str() value_builder.write_string(x.ascii_str())
} }
return value return value_builder.str()
} }
// format flag // format flag
@ -79,7 +80,7 @@ pub fn (cflags []CFlag) c_options_after_target_msvc() []string {
pub fn (cflags []CFlag) c_options_before_target() []string { pub fn (cflags []CFlag) c_options_before_target() []string {
defines, others, _ := cflags.defines_others_libs() defines, others, _ := cflags.defines_others_libs()
mut args := []string{} mut args := []string{cap: defines.len + others.len}
args << defines args << defines
args << others args << others
return args return args