remobjects / SwiftBaseLibrary

Other
92 stars 13 forks source link

Some String changes #12

Closed mhavu closed 4 years ago

mhavu commented 4 years ago

I changed String.init(count:repeatedValue:) with init(repeating:count:) (a change introduced in Swift 3) and added String.utf8CString for CLR and ISLAND (unfortunately no JAVA – which Java version should one target?).

dwarfland commented 4 years ago

Not sure in like thew change to

public var utf8CString: [UTF8Char] {

as thats a lot of overhead when the most common case for this property is to get a raw native byte array to work with the string data (possibly to pass to C APIs or the like)...

mhavu commented 4 years ago

as thats a lot of overhead when the most common case for this property is to get a raw native byte array to work with the string data (possibly to pass to C APIs or the like)...

Yes, I'm using it to get a char* for C APIs, and currently there is no implementation on Island. Isn't it so that the native strings in all the other platforms except Cocoa use wide characters? Should I just add a String extension in my own code then?

dwarfland commented 4 years ago

Yeah, but [UTF8Chat] is a bad way to get a char*, because [T] is a complex type implementing the Swift array type semantics. by comparison, T[] is a "native" array — ie just bytes in memory.

You really wanna keep tis property as UTF8Char[], because then you literally can grab its address and have a char*. if it's [UTF8Char] you then still have to get the real array our of it, which is an extra copy operation, (and just t give you a UTF8Char[] that you could have gotten from the getgo.

if that makes sense?

mhavu commented 4 years ago

Yeah, but [UTF8Chat] is a bad way to get a char*, because [T] is a complex type implementing the Swift array type semantics. by comparison, T[] is a "native" array — ie just bytes in memory.

I wasn't aware of such semantic difference. I'll fix it.

dwarfland commented 4 years ago

this one also failed, for Java :(

mhavu commented 4 years ago

Sorry about that. I get E: Internal error: System.Exception: Invalid tag for constant pool item on Cooper, too.