[baobab/gnome-3-34] Use a hash table to store hardlinks
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/gnome-3-34] Use a hash table to store hardlinks
- Date: Tue, 23 Jun 2020 08:12:15 +0000 (UTC)
commit 9acefae19e668f610e260530ad215b3f0311a49c
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Jun 7 17:03:36 2020 +0200
Use a hash table to store hardlinks
src/baobab-scanner.vala | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 9a8c9f6..63445fd 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -71,20 +71,29 @@ namespace Baobab {
FileAttribute.UNIX_DEVICE + "," +
FileAttribute.ACCESS_CAN_READ;
- struct HardLink {
- uint64 inode;
- uint32 device;
+ [Compact]
+ class HardLink {
+ internal uint64 inode;
+ internal uint32 device;
public HardLink (FileInfo info) {
this.inode = info.get_attribute_uint64 (FileAttribute.UNIX_INODE);
this.device = info.get_attribute_uint32 (FileAttribute.UNIX_DEVICE);
}
+
+ public uint hash () {
+ return direct_hash ((void*) this.inode) ^ direct_hash ((void*) this.device);
+ }
+
+ public bool equal (HardLink other) {
+ return this.inode == other.inode && this.device == other.device;
+ }
}
Thread<void*>? thread = null;
uint process_result_idle = 0;
- HardLink[] hardlinks;
+ GenericSet<HardLink> hardlinks;
GenericSet<File> excluded_locations;
bool successful = false;
@@ -210,14 +219,14 @@ namespace Baobab {
case FileType.REGULAR:
if (child_info.has_attribute (FileAttribute.UNIX_NLINK)) {
if (child_info.get_attribute_uint32 (FileAttribute.UNIX_NLINK) > 1) {
- var hl = HardLink (child_info);
+ var hl = new HardLink (child_info);
// check if we've already encountered this file
if (hl in hardlinks) {
continue;
}
- hardlinks += hl;
+ hardlinks.add ((owned) hl);
}
}
@@ -373,7 +382,7 @@ namespace Baobab {
tmp = results_queue.try_pop ();
}
- hardlinks = null;
+ hardlinks = new GenericSet<HardLink> (HardLink.hash, HardLink.equal);
base.clear ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]