GNOME Bugzilla – Bug 737445
optimise GPrivate
Last modified: 2018-05-24 17:03:16 UTC
We could avoid an extra malloc() in the implementation of GPrivate on Linux. Here's some patches for that. It may also be possible to implement GPrivate more efficiently for ourselves, but that is a story for later... Note that the memcpy() calls in these patches are required to avoid breaking strict aliasing rules. Since the operation is being performed with a small constant size, it is optimised out by the compiler and replaced with a simple assignment.
Created attachment 287174 [details] [review] GPrivate: change return type of internal function g_private_get_impl() was returning a pointer to the pthread_key_t, but every function using this was immediately dereferencing it. Change it so that we dereference the value in the helper function and return it by value.
Created attachment 287175 [details] [review] GPrivate: a nice optimisation We don't know how big a pthread_key_t is, so we malloc() a big enough chunk of memory for it and store a pointer into the GPrivate struct. It turns out, on Linux, pthread_key_t is just an int, so we could much easier just store it directly into the struct.
Review of attachment 287175 [details] [review]: ::: glib/gthread-posix.c @@ +1056,3 @@ + + if G_UNLIKELY (impl == NULL) + g_thread_abort (status, "pthread_key_create (gave non-NULL result twice)"); s/non-NULL/NULL/ here ?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/931.