Peter,

I compared your version with mine on plenty of sample data & they produced 
the same results. Although my version seems to do more copying, the 
difference between them was += 0.01 sec on each run. However, yours is 
simpler and clearer than mine, so I'm now using yours:-)

Thank you!

On Monday, February 27, 2017 at 6:10:14 PM UTC, peterGo wrote:
>
> Mark,
>
> For example,
>
> Go Playground: https://play.golang.org/p/dv48PLY-CD
>
> Peter
>
> On Monday, February 27, 2017 at 11:05:32 AM UTC-5, Mark wrote:
>>
>> Ooops just realised that I didn't enforce the max chars limit. Here's 
>> another version:
>>
>> func CwcharToString(p uintptr, maxchars int) string {
>>     if p == 0 {
>>         return ""
>>     }
>>     uints := make([]uint16, 0, maxchars)
>>     for i, p := 0, uintptr(unsafe.Pointer(p)); i < maxchars; p += 2 {
>>         u := *(*uint16)(unsafe.Pointer(p))
>>         if u == 0 {
>>             break
>>         }
>>         uints = append(uints, u)
>>         i++
>>     }
>>     return string(utf16.Decode(uints))
>> }
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to