extensionUtils: Slightly optimize current extension lookup
When looking for a directory name that matches the extension UUID, we can just as well use GLib's dirname()/basename() functions instead of wrapping the path in a GFile. We also know that the original path corresponds to a regular file and not a directory, so rearrange the loop to avoid a lookup that is guaranteed to fail. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2832>
This commit is contained in:
parent
3289b79433
commit
3451c5a182
@ -98,17 +98,18 @@ function getCurrentExtension() {
|
|||||||
//
|
//
|
||||||
// We don't have to care about the exact composition, all we need
|
// We don't have to care about the exact composition, all we need
|
||||||
// is a string that can be traversed as path and contains the UUID
|
// is a string that can be traversed as path and contains the UUID
|
||||||
const path = extensionLine.slice(extensionLine.indexOf(basePath));
|
let path = extensionLine.slice(extensionLine.indexOf(basePath));
|
||||||
let file = Gio.File.new_for_path(path);
|
|
||||||
|
|
||||||
// Walk up the directory tree, looking for an extension with
|
// Walk up the directory tree, looking for an extension with
|
||||||
// the same UUID as a directory name.
|
// the same UUID as a directory name.
|
||||||
while (file != null) {
|
do {
|
||||||
let extension = extensionManager.lookup(file.get_basename());
|
path = GLib.path_get_dirname(path);
|
||||||
|
|
||||||
|
const dirName = GLib.path_get_basename(path);
|
||||||
|
const extension = extensionManager.lookup(dirName);
|
||||||
if (extension !== undefined)
|
if (extension !== undefined)
|
||||||
return extension;
|
return extension;
|
||||||
file = file.get_parent();
|
} while (path !== '/');
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user