@@ -130,8 +130,7 @@ export class SwiftRuntime {
130
130
return textDecoder . decode ( uint8Memory . subarray ( ptr , ptr + len ) ) ;
131
131
}
132
132
133
- const writeString = ( ptr : pointer , value : string ) => {
134
- const bytes = textEncoder . encode ( value ) ;
133
+ const writeString = ( ptr : pointer , bytes : Uint8Array ) => {
135
134
const uint8Memory = new Uint8Array ( memory ( ) . buffer ) ;
136
135
for ( const [ index , byte ] of bytes . entries ( ) ) {
137
136
uint8Memory [ ptr + index ] = byte
@@ -224,10 +223,9 @@ export class SwiftRuntime {
224
223
break ;
225
224
}
226
225
case "string" : {
227
- // FIXME: currently encode twice
228
226
const bytes = textEncoder . encode ( value ) ;
229
227
writeUint32 ( kind_ptr , JavaScriptValueKind . String ) ;
230
- writeUint32 ( payload1_ptr , this . heap . allocHeap ( value ) ) ;
228
+ writeUint32 ( payload1_ptr , this . heap . allocHeap ( bytes ) ) ;
231
229
writeUint32 ( payload2_ptr , bytes . length ) ;
232
230
break ;
233
231
}
@@ -306,8 +304,8 @@ export class SwiftRuntime {
306
304
writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , payload3_ptr ) ;
307
305
} ,
308
306
swjs_load_string : ( ref : ref , buffer : pointer ) => {
309
- const string = this . heap . referenceHeap ( ref ) ;
310
- writeString ( buffer , string ) ;
307
+ const bytes = this . heap . referenceHeap ( ref ) ;
308
+ writeString ( buffer , bytes ) ;
311
309
} ,
312
310
swjs_call_function : (
313
311
ref : ref , argv : pointer , argc : number ,
0 commit comments