optimisation : Use g_object_newv where possible.

This avoids:
* triple-checking for the GType when type-checking is enabled (see #597260)
* Avoids going through an expensive no-argument checking which landed in
  glib-2.22
* Avoids going through 2 extrac functions (g_object_new -> g_object_new_valist)
This commit is contained in:
Edward Hervey 2009-10-28 09:26:32 +01:00
parent 118509af69
commit 27284628e4
19 changed files with 25 additions and 24 deletions

View file

@ -273,7 +273,7 @@ gst_bus_new (void)
{ {
GstBus *result; GstBus *result;
result = g_object_new (gst_bus_get_type (), NULL); result = g_object_newv (gst_bus_get_type (), 0, NULL);
GST_DEBUG_OBJECT (result, "created new bus"); GST_DEBUG_OBJECT (result, "created new bus");
return result; return result;

View file

@ -281,7 +281,8 @@ gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
} }
factory = factory =
GST_ELEMENT_FACTORY_CAST (g_object_new (GST_TYPE_ELEMENT_FACTORY, NULL)); GST_ELEMENT_FACTORY_CAST (g_object_newv (GST_TYPE_ELEMENT_FACTORY, 0,
NULL));
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name); gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
GST_LOG_OBJECT (factory, "Created new elementfactory for type %s", GST_LOG_OBJECT (factory, "Created new elementfactory for type %s",
g_type_name (type)); g_type_name (type));
@ -405,7 +406,7 @@ gst_element_factory_create (GstElementFactory * factory, const gchar * name)
goto no_type; goto no_type;
/* create an instance of the element, cast so we don't assert on NULL */ /* create an instance of the element, cast so we don't assert on NULL */
element = GST_ELEMENT_CAST (g_object_new (factory->type, NULL)); element = GST_ELEMENT_CAST (g_object_newv (factory->type, 0, NULL));
if (G_UNLIKELY (element == NULL)) if (G_UNLIKELY (element == NULL))
goto no_element; goto no_element;

View file

@ -283,7 +283,7 @@ gst_index_new (void)
{ {
GstIndex *index; GstIndex *index;
index = g_object_new (gst_index_get_type (), NULL); index = g_object_newv (gst_index_get_type (), 0, NULL);
return index; return index;
} }

View file

@ -87,7 +87,7 @@ gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
GstIndexFactory *factory; GstIndexFactory *factory;
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
factory = GST_INDEX_FACTORY (g_object_new (GST_TYPE_INDEX_FACTORY, NULL)); factory = GST_INDEX_FACTORY (g_object_newv (GST_TYPE_INDEX_FACTORY, 0, NULL));
GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name); GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
if (factory->longdesc) if (factory->longdesc)
@ -160,7 +160,7 @@ gst_index_factory_create (GstIndexFactory * factory)
if (newfactory == NULL) if (newfactory == NULL)
return NULL; return NULL;
new = GST_INDEX (g_object_new (newfactory->type, NULL)); new = GST_INDEX (g_object_newv (newfactory->type, 0, NULL));
gst_object_unref (newfactory); gst_object_unref (newfactory);

View file

@ -246,7 +246,7 @@ gst_object_class_init (GstObjectClass * klass)
klass->lock = g_new0 (GStaticRecMutex, 1); klass->lock = g_new0 (GStaticRecMutex, 1);
g_static_rec_mutex_init (klass->lock); g_static_rec_mutex_init (klass->lock);
klass->signal_object = g_object_new (gst_signal_object_get_type (), NULL); klass->signal_object = g_object_newv (gst_signal_object_get_type (), 0, NULL);
/* see the comments at gst_object_dispatch_properties_changed */ /* see the comments at gst_object_dispatch_properties_changed */
gobject_class->dispatch_properties_changed gobject_class->dispatch_properties_changed

View file

@ -245,7 +245,7 @@ gst_plugin_register_static (gint major_version, gint minor_version,
g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE); g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
GST_LOG ("attempting to load static plugin \"%s\" now...", name); GST_LOG ("attempting to load static plugin \"%s\" now...", name);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) { if (gst_plugin_register_func (plugin, &desc, NULL) != NULL) {
GST_INFO ("registered static plugin \"%s\"", name); GST_INFO ("registered static plugin \"%s\"", name);
res = gst_default_registry_add_plugin (plugin); res = gst_default_registry_add_plugin (plugin);
@ -314,7 +314,7 @@ gst_plugin_register_static_full (gint major_version, gint minor_version,
g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE); g_return_val_if_fail (_gst_plugin_inited != FALSE, FALSE);
GST_LOG ("attempting to load static plugin \"%s\" now...", name); GST_LOG ("attempting to load static plugin \"%s\" now...", name);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) { if (gst_plugin_register_func (plugin, &desc, user_data) != NULL) {
GST_INFO ("registered static plugin \"%s\"", name); GST_INFO ("registered static plugin \"%s\"", name);
res = gst_default_registry_add_plugin (plugin); res = gst_default_registry_add_plugin (plugin);
@ -593,7 +593,7 @@ gst_plugin_load_file (const gchar * filename, GError ** error)
} }
if (new_plugin) { if (new_plugin) {
plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
plugin->file_mtime = file_status.st_mtime; plugin->file_mtime = file_status.st_mtime;
plugin->file_size = file_status.st_size; plugin->file_size = file_status.st_size;
plugin->filename = g_strdup (filename); plugin->filename = g_strdup (filename);

View file

@ -320,7 +320,7 @@ static void
plugin_loader_create_blacklist_plugin (GstPluginLoader * l, plugin_loader_create_blacklist_plugin (GstPluginLoader * l,
PendingPluginEntry * entry) PendingPluginEntry * entry)
{ {
GstPlugin *plugin = g_object_new (GST_TYPE_PLUGIN, NULL); GstPlugin *plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
plugin->filename = g_strdup (entry->filename); plugin->filename = g_strdup (entry->filename);
plugin->file_mtime = entry->file_mtime; plugin->file_mtime = entry->file_mtime;

View file

@ -298,7 +298,7 @@ gst_registry_get_default (void)
g_static_mutex_lock (&_gst_registry_mutex); g_static_mutex_lock (&_gst_registry_mutex);
if (G_UNLIKELY (!_gst_registry_default)) { if (G_UNLIKELY (!_gst_registry_default)) {
_gst_registry_default = g_object_new (GST_TYPE_REGISTRY, NULL); _gst_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default)); gst_object_ref_sink (GST_OBJECT_CAST (_gst_registry_default));
} }
registry = _gst_registry_default; registry = _gst_registry_default;

View file

@ -514,7 +514,7 @@ gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
g_free (type_name); g_free (type_name);
return FALSE; return FALSE;
} }
if (G_UNLIKELY ((feature = g_object_new (type, NULL)) == NULL)) { if (G_UNLIKELY ((feature = g_object_newv (type, 0, NULL)) == NULL)) {
GST_ERROR ("Can't create feature from type"); GST_ERROR ("Can't create feature from type");
g_free (type_name); g_free (type_name);
return FALSE; return FALSE;
@ -728,7 +728,7 @@ _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
*in); *in);
unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail); unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
plugin = g_object_new (GST_TYPE_PLUGIN, NULL); plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
/* TODO: also set GST_PLUGIN_FLAG_CONST */ /* TODO: also set GST_PLUGIN_FLAG_CONST */
plugin->flags |= GST_PLUGIN_FLAG_CACHED; plugin->flags |= GST_PLUGIN_FLAG_CACHED;

View file

@ -323,7 +323,7 @@ gst_task_create (GstTaskFunction func, gpointer data)
{ {
GstTask *task; GstTask *task;
task = g_object_new (GST_TYPE_TASK, NULL); task = g_object_newv (GST_TYPE_TASK, 0, NULL);
task->func = func; task->func = func;
task->data = data; task->data = data;

View file

@ -162,7 +162,7 @@ gst_task_pool_new (void)
{ {
GstTaskPool *pool; GstTaskPool *pool;
pool = g_object_new (GST_TYPE_TASK_POOL, NULL); pool = g_object_newv (GST_TYPE_TASK_POOL, 0, NULL);
return pool; return pool;
} }

View file

@ -81,7 +81,7 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
GST_INFO ("registering typefind function for %s", name); GST_INFO ("registering typefind function for %s", name);
factory = g_object_new (GST_TYPE_TYPE_FIND_FACTORY, NULL); factory = g_object_newv (GST_TYPE_TYPE_FIND_FACTORY, 0, NULL);
GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name); GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
g_assert (GST_IS_TYPE_FIND_FACTORY (factory)); g_assert (GST_IS_TYPE_FIND_FACTORY (factory));

View file

@ -115,7 +115,7 @@ gst_xml_dispose (GObject * object)
GstXML * GstXML *
gst_xml_new (void) gst_xml_new (void)
{ {
return GST_XML (g_object_new (GST_TYPE_XML, NULL)); return GST_XML (g_object_newv (GST_TYPE_XML, 0, NULL));
} }
/** /**

View file

@ -192,7 +192,7 @@ gst_adapter_finalize (GObject * object)
GstAdapter * GstAdapter *
gst_adapter_new (void) gst_adapter_new (void)
{ {
return g_object_new (GST_TYPE_ADAPTER, NULL); return g_object_newv (GST_TYPE_ADAPTER, 0, NULL);
} }
/** /**

View file

@ -164,7 +164,7 @@ gst_collect_pads_new (void)
{ {
GstCollectPads *newcoll; GstCollectPads *newcoll;
newcoll = g_object_new (GST_TYPE_COLLECT_PADS, NULL); newcoll = g_object_newv (GST_TYPE_COLLECT_PADS, 0, NULL);
return newcoll; return newcoll;
} }

View file

@ -206,7 +206,7 @@ gst_data_queue_new_full (GstDataQueueCheckFullFunction checkfull,
g_return_val_if_fail (checkfull != NULL, NULL); g_return_val_if_fail (checkfull != NULL, NULL);
ret = g_object_new (GST_TYPE_DATA_QUEUE, NULL); ret = g_object_newv (GST_TYPE_DATA_QUEUE, 0, NULL);
ret->checkfull = checkfull; ret->checkfull = checkfull;
ret->checkdata = checkdata; ret->checkdata = checkdata;
ret->fullcallback = fullcallback; ret->fullcallback = fullcallback;

View file

@ -227,7 +227,7 @@ gst_controller_add_property (GstController * self, GObject * object,
if ((prop = gst_controlled_property_new (object, name))) { if ((prop = gst_controlled_property_new (object, name))) {
/* if we don't have a controller object yet, now is the time to create one */ /* if we don't have a controller object yet, now is the time to create one */
if (!self) { if (!self) {
self = g_object_new (GST_TYPE_CONTROLLER, NULL); self = g_object_newv (GST_TYPE_CONTROLLER, 0, NULL);
self->object = g_object_ref (object); self->object = g_object_ref (object);
/* store the controller */ /* store the controller */
g_object_set_qdata (object, priv_gst_controller_key, self); g_object_set_qdata (object, priv_gst_controller_key, self);

View file

@ -110,7 +110,7 @@ gst_interpolation_control_source_reset (GstInterpolationControlSource * self)
GstInterpolationControlSource * GstInterpolationControlSource *
gst_interpolation_control_source_new (void) gst_interpolation_control_source_new (void)
{ {
return g_object_new (GST_TYPE_INTERPOLATION_CONTROL_SOURCE, NULL); return g_object_newv (GST_TYPE_INTERPOLATION_CONTROL_SOURCE, 0, NULL);
} }
/** /**

View file

@ -566,7 +566,7 @@ gst_lfo_control_source_reset (GstLFOControlSource * self)
GstLFOControlSource * GstLFOControlSource *
gst_lfo_control_source_new (void) gst_lfo_control_source_new (void)
{ {
return g_object_new (GST_TYPE_LFO_CONTROL_SOURCE, NULL); return g_object_newv (GST_TYPE_LFO_CONTROL_SOURCE, 0, NULL);
} }
static gboolean static gboolean