floooh / sokol-nim

nim bindings for https://github.com/floooh/sokol
MIT License
83 stars 15 forks source link

Optimization suggestions #3

Closed RSDuck closed 6 years ago

RSDuck commented 6 years ago

You annotated all of your structures with bycopy, but I haven't found a place where it would be needed. Leaving it out would allow the Nim compiler to just pass a pointer which is obviously much faster. The pass by pointer/pass by value is hidden, so the semantic doesn't change. It isn't allowed modify a non var parameter anyway and if you assign a variable with the value of the parameter, all values are copied.

The second thing is the proc unsafeAddr which can be used to retrive a pointer to a location of a let or non var parameter. This is very useful in situations where you can guarantee that the memory the pointer is pointing to won't be modified, like e.g. here https://github.com/floooh/sokol-nim/blob/master/sokol/gfx.nim#L591

EDIT: also I would annotate the types instead with the pure pragma to ensure they are layed out as plain C structs

floooh commented 6 years ago

Thanks for the suggestions. I'm quite a Nim noob, I think I was looking at some existing C bindings and copied what they've done. If you'd like to provide a pull request with these suggestions I'm happy to merge it :)