@@ -130,8 +130,7 @@ export class SwiftRuntime {
130130 return textDecoder . decode ( uint8Memory . subarray ( ptr , ptr + len ) ) ;
131131 }
132132
133- const writeString = ( ptr : pointer , value : string ) => {
134- const bytes = textEncoder . encode ( value ) ;
133+ const writeString = ( ptr : pointer , bytes : Uint8Array ) => {
135134 const uint8Memory = new Uint8Array ( memory ( ) . buffer ) ;
136135 for ( const [ index , byte ] of bytes . entries ( ) ) {
137136 uint8Memory [ ptr + index ] = byte
@@ -224,10 +223,9 @@ export class SwiftRuntime {
224223 break ;
225224 }
226225 case "string" : {
227- // FIXME: currently encode twice
228226 const bytes = textEncoder . encode ( value ) ;
229227 writeUint32 ( kind_ptr , JavaScriptValueKind . String ) ;
230- writeUint32 ( payload1_ptr , this . heap . allocHeap ( value ) ) ;
228+ writeUint32 ( payload1_ptr , this . heap . allocHeap ( bytes ) ) ;
231229 writeUint32 ( payload2_ptr , bytes . length ) ;
232230 break ;
233231 }
@@ -306,8 +304,8 @@ export class SwiftRuntime {
306304 writeValue ( result , kind_ptr , payload1_ptr , payload2_ptr , payload3_ptr ) ;
307305 } ,
308306 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 ) ;
311309 } ,
312310 swjs_call_function : (
313311 ref : ref , argv : pointer , argc : number ,
0 commit comments