Skip to content

Commit fde929e

Browse files
committed
cgen: remove tos3() call: part 1
1 parent dd1ee39 commit fde929e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

vlib/v/gen/cgen.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,12 @@ fn (mut g Gen) expr(node ast.Expr) {
11271127
// `C.printf("hi")` => `printf("hi");`
11281128
g.write('"$escaped_val"')
11291129
} else {
1130+
// TODO calculate the literal's length in V, it's a bit tricky with all the
1131+
// escape characters.
1132+
// Clang and GCC optimize `strlen("lorem ipsum")` to `11`
1133+
// g.write('tos4("$escaped_val", strlen("$escaped_val"))')
1134+
// g.write('tos4("$escaped_val", $it.val.len)')
1135+
// g.write('_SLIT("$escaped_val")')
11301136
g.write('tos3("$escaped_val")')
11311137
}
11321138
}
@@ -2727,7 +2733,7 @@ fn (g Gen) type_default(typ table.Type) string {
27272733
}
27282734
*/
27292735
match sym.name {
2730-
'string' { return 'tos3("")' }
2736+
'string' { return '(string){.str=""}' }
27312737
'rune' { return '0' }
27322738
else {}
27332739
}

vlib/v/gen/cheaders.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ extern wchar_t **_wenviron;
173173
174174
175175
//============================== HELPER C MACROS =============================*/
176+
//#define tos4(s, slen) ((string){.str=(s), .len=(slen)})
177+
#define _SLIT(s) ((string){.str=(s), .len=(strlen(s))})
176178
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
177179
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
178180
#define _IN_MAP(val, m) map_exists(m, val)

0 commit comments

Comments
 (0)