y-crdt / ydotnet

.NET bindings for yrs.
MIT License
35 stars 9 forks source link

ReferenceAccessor should be a factory #47

Closed SebastianStehle closed 10 months ago

SebastianStehle commented 11 months ago

The reference accessor is actually super weird. First, an object is created. Then we check the handle and discard this object again. This puts unnecessary pressure on the GC.

I think we should just rename it to ReferenceFactory and refactor it to methods like this:

public static Output? Output(nint handle, bool shouldDispose)
{
     return handle == nint.Zero ? null : new Output(handle, shouldDispose);
}

Depending on #48 it might event be obsolete.

Please assign me, if you agree. Happy to provide a PR.

LSViana commented 11 months ago

Hi, @SebastianStehle!

I like this idea. I'm not completely happy with ReferenceAccessor because it's just static code to centralize some operations but I didn't put a lot of thought here. It could be better.

However, let's finish #48 first then we discuss what to do here.