Why search for userdata in a separate data structure?
Closed this issue · 2 comments
I noticed that the code does the following:
ud_t *ud = userdata(p);
That function searches a mapping between the pointer created by new Fl_Widget and the userdata.
Was there a particular problem you were trying to solve that could only be done in this way?
As an alternative for userdata you can create a struct with all the data you need in it and return it and pass it around. This means no need for searching and simpler code.
The ud is precisely the struct with the data I need and pass around.
The reason I usually have that sort of mapping, when I bind libraries, is that there are often situations where I have to retrieve the userdata from the pointer (not only the other way round).
I just gave a quick look at the code and I noticed that there are indeed places where I make an unnecessary search, which I could easily avoid by modyfing the check_Xxx() and test_Xxx() functions to
make them optionally return the ud together with the pointer. In other binding libraries I do this, in fact.
Not sure if this is a big deal, however, they are fast searches. Did you experience delays caused by them?
No delay at all. I agree that the code is fast. My only concern is code maintainability. You have to remember to keep that data structure up to date at all times otherwise you will experience bugs.
I will note that right now I have not noticed any bugs because of this. It was just something I was wondering about. I think for now we can close this and forget about this.