GNOME Bugzilla – Bug 670969
GSequence lookup may fail if there was no sort prior to lookup
Last modified: 2012-03-02 14:09:08 UTC
If you add e.g. strings to a GSequence with the append method, then using the lookup function may fail in many cases and return null, even though the data is there. If a sort was done prior using lookup or the insertion of data was done using insert_sorted, it always works as expected. I think prepending and appending data to a GSequence should internally mark the it as dirty and sorting should mark it as clean. A lookup to a dirty sequence should lead to a sort, which is done before the actual lookup.
not sure i agree with this. how do we know the user is not taking care to append items in sorted order?
Ok. Good point. I came across this because it is not documented anywhere. If it was mentioned somewhere, I could have taken care. Want a patch?
Created attachment 208575 [details] Testcase Here is a testcase. The lookup fails in 50%
Created attachment 208612 [details] [review] proposed patch Added proposed patch for documenting this special behaviour of GSequence.
Created attachment 208704 [details] [review] GSequence: add note about lookup requiring sorting Here's an updated patch. I tweaked the wording a little and copied it to g_sequence_search() as well (which is also affected by the same problem). Does this look okay to you?
Yes, okay for me.
Attachment 208704 [details] pushed as 00f1e1f - GSequence: add note about lookup requiring sorting Thanks for the report.