After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 790310 - speedup path canonicalization in GResourceFile
speedup path canonicalization in GResourceFile
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-11-14 05:52 UTC by Christian Hergert
Modified: 2017-11-14 23:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
speedup path canonicalization for gresourcefile (3.89 KB, patch)
2017-11-14 05:52 UTC, Christian Hergert
needs-work Details | Review
gresourcefile: simplify path canonicalization (6.29 KB, patch)
2017-11-14 12:48 UTC, Christian Hergert
committed Details | Review

Description Christian Hergert 2017-11-14 05:52:55 UTC
Created attachment 363554 [details] [review]
speedup path canonicalization for gresourcefile

The previous version did a lot of strlen() and memmove(), which can be avoided. I happened across the code and decided to spend a few minutes cleaning it up while trying to grok what it was doing.

Not essential, but it's faster and easier to read what is going on.
Comment 1 Alexander Larsson 2017-11-14 08:15:11 UTC
Looks good to me.
Comment 2 Bastien Nocera 2017-11-14 10:03:21 UTC
Review of attachment 363554 [details] [review]:

> functions. memrchr() was not used due to it's lack of portability.

its
Comment 3 Philip Withnall 2017-11-14 11:02:39 UTC
Review of attachment 363554 [details] [review]:

Thanks for this, it looks good to me, but I’d like to see some unit tests (and a fix for Bastien’s nitpick) before it gets merged.

::: gio/gresourcefile.c
@@ +163,3 @@
+
+static char *
+canonicalize_filename (const char *in)

It would be good to have a documentation comment summarising what ‘canonicalisation’ entails.

I’d also like some unit tests which call g_resource_file_new_for_path() with all kinds of non-canonical filename to get good coverage of the new canonicalize_filename().
Comment 4 Christian Hergert 2017-11-14 12:48:15 UTC
Created attachment 363577 [details] [review]
gresourcefile: simplify path canonicalization

Previously, the path canonicalization for resources had liberal use of
strlen() and memmove() while walking through the path. This patch avoids
any secondary strlen() and removes all use of memmove().

A single allocation is created up front as we should only ever need one
additional byte more than then length of the incoming path string.

To keep the implementation readable, the mechanics are kept in external
functions. memrchr() was not used due to its lack of portability.

This is faster in every test case I've tested. Paths that contain
relative ../ have the most speedup.
Comment 5 Christian Hergert 2017-11-14 12:50:41 UTC
The updated patch includes documentation on the canonical form and adds a new unit test for a number of degenerate cases. Commit message also fixed.
Comment 6 Philip Withnall 2017-11-14 14:15:01 UTC
Review of attachment 363577 [details] [review]:

That’s great, thanks. One minor comment, but you can fix that before pushing.

::: gio/tests/resources.c
@@ +159,3 @@
+test_resource_file_path (void)
+{
+  static struct {

`const`
Comment 7 Christian Hergert 2017-11-14 23:14:29 UTC
Attachment 363577 [details] pushed as 38ffcd2 - gresourcefile: simplify path canonicalization