Skip to content
  • Allison Karlitskaya's avatar
    GObject: substantially rework g_object_new() · bfa8bef7
    Allison Karlitskaya authored
    Make a number of improvements to g_object_new():
    
     - instead of looking up the GParamSpec for the named property once in
       g_object_new() (in order to collect) and then again in g_object_newv
       (when actually setting the property), g_object_new_internal() is a
       new function that takes the GParamSpec on the interface to avoid the
       second lookup
    
     - in the case that ->constructor() is not set, we need not waste time
       creating an array of GObjectConstructParam to pass in.  Just directly
       iterate the list of parameters, calling set_property() on each.
    
     - instead of playing with linked lists to keep track of the construct
       properties, realise that the number of construct properties that we
       will set is exactly equal to the length of the construct_properties
       list on GObjectClass and the only thing that may change is where the
       value comes from (in the case that it was passed in)
    
       This assumption was already implicit in the existing code and can be
       seen from the sizing of the array used to hold the construct
       properties, but it wasn't taken advantage of to make things simpler.
    
     - instead of allocating and filling a separate array of the
       non-construct properties just re-iterate the passed-in list and set
       all properties that were not marked G_PARAM_CONSTRUCT (since the ones
       that were construct params were already used during construction)
    
     - use the new g_param_spec_get_default_value() API instead of
       allocating and setting the GValue for each construct property that
       wasn't passed from the user
    
    Because we are now iterating the linked list of properties in-order we
    need to append to that list during class initialising instead of
    prepending.
    
    These changes show a very small improvement on the simple-construction
    performance testcase (probably just noise) and they improve the
    complex-construction case by ~30%.
    
    Thanks to Alex Larsson for reviews and fixes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698056
    bfa8bef7