Commit Graph

1985 Commits

Author SHA1 Message Date
Philip Withnall
2b437402e8 Merge branch 'gobject-speedup7' into 'main'
Avoid g_object_ref/unref in some cases

See merge request GNOME/glib!2721
2022-06-06 17:53:42 +00:00
Philip Withnall
f8c5d71104 Merge branch 'gobject-speedup9' into 'main'
Avoid g_type_class_peek

See merge request GNOME/glib!2723
2022-06-06 17:16:33 +00:00
Matthias Clasen
e70a4eef77 Avoid g_object_ref/unref in some cases
We only need to take a ref on the object when
we call out to external code (ie around
->dispatch_properties_changed). If we avoid
the signal emission, we can avoid the ref/unref
too. This is not currently happening, but
might in the future.
2022-06-06 12:33:34 -04:00
Matthias Clasen
19551ac983 Avoid g_type_class_peek
Most of the time, properties belong to the class
we set them on. Check that first, before going
into GType, which takes locks and whatnot.
2022-06-06 11:51:55 -04:00
Matthias Clasen
a4940943e5 Move deprecation warnings to object_set_property
A small reorg that reduces the code and matches
what we do for object_get_property.

Note that as a consequence of this change, we now
check the deprecated flag on the redirected property,
not on the original when setting properties. This
matches what we were already doing for getting
properties.
2022-06-06 11:29:16 -04:00
Matthias Clasen
d97c948567 Don't inline deprecation warnings
The code that emits property deprecation warnings
rarely runs, and doesn't need to be inlined
everywhere. It is enough to inline the check for
the deprecation flag.
2022-06-06 11:29:14 -04:00
Philip Withnall
d730cfcdf4 Merge branch 'gobject-speedup2' into 'main'
Simplify g_object_new_with_properties

See merge request GNOME/glib!2713
2022-06-06 15:18:01 +00:00
Philip Withnall
d7ff2b3ad1 Merge branch 'gobject-speedup5' into 'main'
Don't copy values in g_object_new

See merge request GNOME/glib!2716
2022-06-06 13:51:13 +00:00
Philip Withnall
22fea9d24a Merge branch 'gobject-speedup3' into 'main'
Simplify g_object_notify_by_pspec

See merge request GNOME/glib!2714
2022-06-06 13:02:52 +00:00
Matthias Clasen
ec69e7c463 Simplify g_object_new_with_properties
This function was doing an unnecessary extra
copy of the GValues. We can avoid that.
2022-06-03 07:10:08 -04:00
Matthias Clasen
149b0f03b4 Simplify g_object_notify_by_pspec
Fold get_notify_pspec into its only caller.
2022-06-01 19:33:04 -04:00
Matthias Clasen
95caffcd26 Don't copy values during g_object_set
It is safe not to copy arguments here,
because we are not emitting any signals
before we are done setting the values
as properties.

This matches what we do for g_object_new now.
2022-06-01 18:22:10 -04:00
Matthias Clasen
d50bc3c1c3 Don't copy values in g_object_new
We can safely use the values without copying here.
This is safe because we are not emitting any
signals before we are done setting the values
as properties.
2022-06-01 18:20:41 -04:00
Simon McVittie
804c45324e Merge branch 'test-verbose-output' into 'main'
tests: Remove various bits of overly-verbose test output

See merge request GNOME/glib!2704
2022-06-01 17:31:53 +00:00
Matthias Clasen
72a682950d gobject: Drop an unused quark
quark_in_construction is only used if
we don't have per-instance flags.
2022-05-31 16:13:18 -04:00
Philip Withnall
0611999fed tests: Remove various bits of overly-verbose test output
None of these messages are particularly helpful, but they increase the
overall test log output size, which has to be stored by the CI for every
test run.

With these messages removed, the size of a full test log is reduced from
6.5MB to 1.8MB for me.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-31 15:21:46 +01:00
Philip Withnall
cf988d2a06 Merge branch 'final-type-speedup' into 'main'
gtype: Speed up type checks for final types

See merge request GNOME/glib!2700
2022-05-30 11:01:33 +00:00
Matthias Clasen
0ddea2d8e2 gtype: Speed up type checks for final types
If a type is final, it is enough to compare the
instance type for equality, since it can't have
a derived type.
2022-05-30 00:10:32 -04:00
Matthias Clasen
3db1d260ee testsuite: Make tests not fail in !debug builds
Some of our tests rely on on warning that only
occur in debug builds. Skip them in non-debug
builds.

Fixes: #2656
2022-05-28 08:02:16 -04:00
Philip Withnall
81fd75b4bb Merge branch 'move_gobject_tests' into 'main'
Moving gobject tests from tests/gobjects to gobjects/tests

See merge request GNOME/glib!2550
2022-05-26 18:37:19 +00:00
Emmanuel Fleury
4e02be948b Moving gobject tests from tests/gobjects to gobjects/tests
The test files concerned are:

- tests/gobjects/accumulator.c
- tests/gobjects/defaultiface.c
- tests/gobjects/deftype.c
- tests/gobjects/dynamictype.c
- tests/gobjects/override.c
- tests/gobjects/references.c
- tests/gobjects/signals.c
- tests/gobjects/singleton.c

Related to issue #1434
2022-05-26 19:13:19 +01:00
Philip Withnall
ed84b8f468 tests: Port GObject tests from g_thread_create() to g_thread_new()
To avoid warnings about deprecated functions.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1434
2022-05-26 18:37:35 +01:00
Emmanuel Fleury
70401ae8c3 Moving tests/refcount/ directory to gobject/tests/
Modified by Philip Withnall to omit the subdirectory and drop the
`refcount` suite as both seem like unnecessary over-categorisation.

Related to issue #1434
2022-05-26 18:37:35 +01:00
Matthias Clasen
ecc641de71 Avoid malloc for construct params
Stack-allocate the GObjectConstructParams (except for
extreme cases), for a small speedup of object construction.
2022-05-26 09:47:23 -04:00
Matthias Clasen
f7119a7935 Keep a count of construct params
This avoids walking the construct params list
one extra time just to count when constructing
objects, for a small speedup of object construction
in the presence of construct params.
2022-05-26 09:47:23 -04:00
Philip Withnall
f157c7d0d3 gparamspecs: Tidy up a precondition
Move the `if` into the precondition assertion, eliminating one line of
code and making the function preconditions clearer to static analysers.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-25 14:44:48 +01:00
Philip Withnall
96f4c2b095 gparamspecs: Remove redundant NULL checks
`g_param_spec_internal()` can never return `NULL`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-25 14:44:48 +01:00
Matthias Clasen
c72de9dd99 gobject: Use value_is_valid
Avoid GValue transformation when we can, using
the new value_is_valid vfunc.

This is particularly useful for string properties,
where g_value_transform will make a copy of the string.
2022-05-25 14:25:18 +01:00
Matthias Clasen
b0d15068c4 gparamspec: Test individual paramspec is_valid() implementations
Test many of the paramspec implementations
at least a little bit.
2022-05-25 14:25:18 +01:00
Matthias Clasen
c8e14df6f7 Add another test for g_param_value_is_valid
Add a test that exercises the fallback
in g_param_value_is_valid.
2022-05-23 15:51:33 -04:00
Matthias Clasen
24925658f5 Add tests for g_param_value_is_valid 2022-05-23 15:51:33 -04:00
Matthias Clasen
dacfe8c88a param: Add g_param_value_is_valid
This is wrapper for the new value_is_valid vfunc,
but it falls back to using value_validate to
obtain the same information.
2022-05-23 15:48:28 -04:00
Matthias Clasen
bdc8b025c5 param: Add a value_is_valid vfunc
In constrast to value_validate, this one does not
modify the passed-in value, so we can avoid the cost
of copying the GValue beforehand.
It is optional, but we set it for most of the
builtin pspec types.
2022-05-23 15:48:28 -04:00
Matthias Clasen
b7be0f95a8 gobject: Speed up finalization
Move the warning about finalize-during-construction
to debug-only.
2022-05-23 09:20:46 -04:00
Matthias Clasen
fa8c7c0da6 gobject: Use g_datalist_id_remove_multiple
This speeds up object finalization a little.
2022-05-23 09:19:45 -04:00
Philip Withnall
7de0fcd628 Merge branch 'gobject-speedups2' into 'main'
Avoid g_type_peek_value_table

See merge request GNOME/glib!2674
2022-05-23 11:00:23 +00:00
Matthias Clasen
f2a085d8ea Avoid g_type_peek_value_table
In several places we do paired calls of g_value_init
and g_value_unset, both of which peek the value table.
We can avoid half of that cost by remembering the value
table, instead of looking it up again.

This uses the new G_VALUE_COLLECT_INIT2 macro.
2022-05-23 06:35:55 -04:00
Matthias Clasen
aaef7f30b3 value: Add G_VALUE_COLLECT_INIT2
Add a variant of the G_VALUE_COLLECT_INIT() macro
that provides the GTypeValueTable to the caller.
2022-05-23 05:57:36 -04:00
TestingPlant
da7a31a052 Rename user data parameters to user_data
The user data parameters in callbacks need to be named user_data to
generate correct closure attributes in the introspection data. This
updates parameters missed in GNOME/glib!2633.
2022-05-22 01:06:37 +00:00
Matthias Clasen
0a3a0894f9 Merge branch 'gtype-speedups' into 'main'
gtype: small optimization

See merge request GNOME/glib!2672
2022-05-20 13:43:17 +00:00
Philip Withnall
1f42078ace Merge branch 'param-speedups' into 'main'
param: Avoid strcmps

See merge request GNOME/glib!2673
2022-05-20 13:15:39 +00:00
Matthias Clasen
e80d2bc1ca Add a test for g_type_is_a
Check that the macro and function versions
of g_type_is_a work the same.
2022-05-20 09:08:09 -04:00
Matthias Clasen
22f51b87a2 gtype: Speed up g_type_is_a
As noticed by Christian Hergert: We can reduce
some overhead by checking for exact type
equality first. According to Christian, around
3% of g_type_is_a calls are exact equalities.
2022-05-20 09:08:09 -04:00
Matthias Clasen
55700948eb param: Drop a pointless function
There is nothing to validate for boxed
parameters, so we don't need a validate
function for these.
2022-05-20 08:20:56 -04:00
Matthias Clasen
51215bf7b8 param: Avoid strchrs
Using prefixed property names like GtkWidget::visible
is very deprectated and basically never done. So avoid
paying the strchr cost before doing the first lookup.
2022-05-20 08:20:56 -04:00
Matthias Clasen
91dafa85fc param: Avoid strcmps
Most of the time, we are dealing with static strings,
and we can compare them directly and avoid the strcmp.

Note that triggering this optimization requires
properties to be marked as G_PARAM_STATIC_NAME.
2022-05-20 08:20:56 -04:00
Philip Withnall
3c14b6846d docs: Standardise property ID enums in examples
Drop the redundant `PROP_0` (which isn’t a real property) and initialise
the first member of the enum instead.

Add a typedef so that the enum type can be used in `switch` statements
in `get_property()` and `set_property()` vfuncs. This allows
`-Wswitch-enum` to be used to improve type safety.

The examples here don’t have `get_property()` or `set_property()`
vfuncs, but people might copy/paste the code to somewhere which does.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-20 12:57:36 +01:00
Philip Withnall
8f9c5090db docs: Use G_PARAM_STATIC_STRINGS in examples and explain it more
Make it a bit clearer in the documentation that using
`G_PARAM_STATIC_STRINGS` everywhere is a good thing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-05-20 12:57:36 +01:00
Matthias Clasen
c492f4aec2 gtype: small optimization
These warnings are never seen at runtime, so they
are evidently very unlikely. Tell the compiler that.
2022-05-20 07:20:19 -04:00
Philip Withnall
caf6d99fbe Merge branch 'win32-fd' into 'main'
gio: various unix/fd-related enablement on win32

See merge request GNOME/glib!2656
2022-05-18 14:01:43 +00:00