From a785428311d83ac6e42b150fa696c831957e1d98 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 3 Jan 2020 13:19:29 +0000 Subject: use a set instead of an array --- lib/MaildirIndexer/Index/ByRef.rakumod | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/MaildirIndexer/Index/ByRef.rakumod b/lib/MaildirIndexer/Index/ByRef.rakumod index f9fc4f9..6e5b7f5 100644 --- a/lib/MaildirIndexer/Index/ByRef.rakumod +++ b/lib/MaildirIndexer/Index/ByRef.rakumod @@ -5,7 +5,7 @@ use MaildirIndexer::LogTimelineSchema; use MaildirIndexer::Email; has Str %!id-for-file; -has Array[Str] %!mailboxes-for-id; +has SetHash %!mailboxes-for-id; method dump() { say "{.key} → {.value}" for %!id-for-file; @@ -20,7 +20,7 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { my $id = $email.message-id or return; %!id-for-file{ $email.path } = $id; - %!mailboxes-for-id{ $id }.push($mailbox); + %!mailboxes-for-id{ $id }{$mailbox}=1; return; } } @@ -28,10 +28,8 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { method del-path(IO:D $file, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByRef'),:$mailbox, -> { my $id = %!id-for-file{ $file.path }:delete or return; - with %!mailboxes-for-id{ $id } { - with .grep($mailbox):k -> $pos { - .splice($pos,1); - } + with %!mailboxes-for-id{ $id } -> $boxes { + $boxes{$mailbox}:delete; } return; } @@ -41,7 +39,7 @@ method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) { my Str $result; MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByRef'), -> { for |$email.refs() -> $ref { - with %!mailboxes-for-id{$ref} { $result = .[*-1] } + with %!mailboxes-for-id{$ref} { $result = .keys.sort.[0] } } } return $result; -- cgit v1.2.3