mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-31 22:23:39 +02:00
gfileutils: Improve performance of g_canonicalize_filename()
Improve the performance of canonicalising filenames with many `..` or `.` components, by modifying the path inline rather than calling `memmove()`. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2541
This commit is contained in:
committed by
Philip Withnall
parent
72377e3b6e
commit
9a30a495ec
@@ -1051,6 +1051,18 @@ test_paths (void)
|
||||
{ "///triple/slash", ".", "/triple/slash" },
|
||||
{ "//double/slash", ".", "//double/slash" },
|
||||
{ "/cwd/../with/./complexities/", "./hello", "/with/complexities/hello" },
|
||||
{ "/", ".dot-dir", "/.dot-dir" },
|
||||
{ "/cwd", "..", "/" },
|
||||
{ "/etc", "hello/..", "/etc" },
|
||||
{ "/etc", "hello/../", "/etc" },
|
||||
{ "/", "..", "/" },
|
||||
{ "/", "../", "/" },
|
||||
{ "/", "/..", "/" },
|
||||
{ "/", "/../", "/" },
|
||||
{ "/", ".", "/" },
|
||||
{ "/", "./", "/" },
|
||||
{ "/", "/.", "/" },
|
||||
{ "/", "/./", "/" },
|
||||
#else
|
||||
{ "/etc", "../usr/share", "\\usr\\share" },
|
||||
{ "/", "/foo/bar", "\\foo\\bar" },
|
||||
@@ -1066,6 +1078,18 @@ test_paths (void)
|
||||
{ "///triple/slash", ".", "\\triple\\slash" },
|
||||
{ "//double/slash", ".", "//double/slash\\" },
|
||||
{ "/cwd/../with/./complexities/", "./hello", "\\with\\complexities\\hello" },
|
||||
{ "/", ".dot-dir", "/.dot-dir" },
|
||||
{ "/cwd", "..", "/" },
|
||||
{ "/etc", "hello/..", "/etc" },
|
||||
{ "/etc", "hello/../", "/etc" },
|
||||
{ "/", "..", "/" },
|
||||
{ "/", "../", "/" },
|
||||
{ "/", "/..", "/" },
|
||||
{ "/", "/../", "/" },
|
||||
{ "/", ".", "/" },
|
||||
{ "/", "./", "/" },
|
||||
{ "/", "/.", "/" },
|
||||
{ "/", "/./", "/" },
|
||||
|
||||
{ "\\etc", "..\\usr\\share", "\\usr\\share" },
|
||||
{ "\\", "\\foo\\bar", "\\foo\\bar" },
|
||||
@@ -1081,6 +1105,18 @@ test_paths (void)
|
||||
{ "\\\\\\triple\\slash", ".", "\\triple\\slash" },
|
||||
{ "\\\\double\\slash", ".", "\\\\double\\slash\\" },
|
||||
{ "\\cwd\\..\\with\\.\\complexities\\", ".\\hello", "\\with\\complexities\\hello" },
|
||||
{ "\\", ".dot-dir", "\\.dot-dir" },
|
||||
{ "\\cwd", "..", "\\" },
|
||||
{ "\\etc", "hello\\..", "\\etc" },
|
||||
{ "\\etc", "hello\\..\\", "\\etc" },
|
||||
{ "\\", "..", "\\" },
|
||||
{ "\\", "..\\", "\\" },
|
||||
{ "\\", "\\..", "\\" },
|
||||
{ "\\", "\\..\\", "\\" },
|
||||
{ "\\", ".", "\\" },
|
||||
{ "\\", ".\\", "\\" },
|
||||
{ "\\", "\\.", "\\" },
|
||||
{ "\\", "\\.\\", "\\" },
|
||||
#endif
|
||||
};
|
||||
const guint n_canonicalize_filename_checks = G_N_ELEMENTS (canonicalize_filename_checks);
|
||||
|
Reference in New Issue
Block a user