From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 02/04: micro-optimisation for Maildir#maildir_labels
Date: Sun, 19 Jul 2026 18:11:17 +1000 [thread overview]
Message-ID: <20260719081116.21ED2218206@bl2.djc.id.au> (raw)
In-Reply-To: <178444867564.48613.6024460618149236020@bl2.djc.id.au>
New commit on branch develop:
https://supmua.dev/git/sup/commit/e336a0e83da82f53be2cf5e5d8911ceeb096825a.html
commit e336a0e83da82f53be2cf5e5d8911ceeb096825a
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sun May 3 17:07:40 2026 +1000
micro-optimisation for Maildir#maildir_labels
Refactor to avoid repeatedly applying a regexp to the message filename
to extract every maildir flag individually.
The =~ operator shows up as frequently called in a profile of indexing
a maildir from scratch, and I was just looking for some likely
candidates where it can be removed. I don't think this made any overall
difference to indexing speed but it's a reasonable cleanup.
---
Manifest.txt | 1 +
lib/sup/maildir.rb | 33 +++++++++++++++++++++------------
test/unit/test_maildir.rb | 21 +++++++++++++++++++++
3 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/Manifest.txt b/Manifest.txt
index 4419a339..dfdeb6a6 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -183,6 +183,7 @@ test/unit/test_horizontal_selector.rb
test/unit/test_index.rb
test/unit/test_line_cursor_mode.rb
test/unit/test_locale_fiddler.rb
+test/unit/test_maildir.rb
test/unit/test_person.rb
test/unit/test_rmail_message.rb
test/unit/util/test_query.rb
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
index 1883844a..1c3aecd1 100644
--- a/lib/sup/maildir.rb
+++ b/lib/sup/maildir.rb
@@ -189,20 +189,29 @@ class Maildir < Source
end
def maildir_labels id
- (seen?(id) ? [] : [:unread]) +
- (trashed?(id) ? [:deleted] : []) +
- (flagged?(id) ? [:starred] : []) +
- (passed?(id) ? [:forwarded] : []) +
- (replied?(id) ? [:replied] : []) +
- (draft?(id) ? [:draft] : [])
+ flags = maildir_flags id
+ labels = []
+ labels << :unread unless flags.member? :seen
+ labels << :deleted if flags.member? :trashed
+ labels << :starred if flags.member? :flagged
+ labels << :forwarded if flags.member? :passed
+ labels << :replied if flags.member? :replied
+ labels << :draft if flags.member? :draft
+ labels
end
- def draft? id; maildir_data(id)[2].include? "D"; end
- def flagged? id; maildir_data(id)[2].include? "F"; end
- def passed? id; maildir_data(id)[2].include? "P"; end
- def replied? id; maildir_data(id)[2].include? "R"; end
- def seen? id; maildir_data(id)[2].include? "S"; end
- def trashed? id; maildir_data(id)[2].include? "T"; end
+ def maildir_flags id
+ maildir_data(id)[2].each_char.map do |c|
+ case c
+ when 'D' then :draft
+ when 'F' then :flagged
+ when 'P' then :passed
+ when 'R' then :replied
+ when 'S' then :seen
+ when 'T' then :trashed
+ end
+ end
+ end
def valid? id
File.exist? File.join(@dir, id)
diff --git a/test/unit/test_maildir.rb b/test/unit/test_maildir.rb
new file mode 100644
index 00000000..a83bab01
--- /dev/null
+++ b/test/unit/test_maildir.rb
@@ -0,0 +1,21 @@
+require 'test_helper'
+require 'sup'
+require 'sup/maildir'
+
+module Redwood
+
+class TestMaildir < Minitest::Test
+ def test_flag_parsing
+ maildir = Maildir.new "maildir:/nowhere"
+ labels = maildir.labels? "asdf:2,S"
+ assert_equal [], labels
+ labels = maildir.labels? "asdf:2,"
+ assert_equal [:unread], labels
+ labels = maildir.labels? "asdf:2,DFPRST"
+ assert_equal [:deleted, :starred, :forwarded, :replied, :draft], labels
+ labels = maildir.labels? "asdf:2,DFPRT"
+ assert_equal [:unread, :deleted, :starred, :forwarded, :replied, :draft], labels
+ end
+end
+
+end
next prev parent reply other threads:[~2026-07-19 8:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-19 8:11 [sup.git] branch develop updated (246af746 -> c20d8fe5) Dan Callaghan
2026-07-19 8:11 ` [sup.git] 01/04: contrib/nix/gem-install-shell.nix: update to Ruby 4.0 Dan Callaghan
2026-07-19 8:11 ` Dan Callaghan [this message]
2026-07-19 8:11 ` [sup.git] 03/04: drop unused indexable_content methods Dan Callaghan
2026-07-19 8:11 ` [sup.git] 04/04: don't fix_encoding! in Message#indexable_body Dan Callaghan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260719081116.21ED2218206@bl2.djc.id.au \
--to=dan@bl2.djc.id.au \
--cc=djc@djc.id.au \
--cc=sup-commits@supmua.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox