From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS55 158.130.0.0/16 X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (tor-exit-node.seas.upenn.edu [158.130.0.242]) by dcvr.yhbt.net (Postfix) with ESMTP id 7632B20A93 for ; Sat, 7 Jan 2017 01:45:12 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 8/9] searchmsg: favor direct hash access over accessor methods Date: Sat, 7 Jan 2017 01:44:51 +0000 Message-Id: <20170107014452.9657-9-e@80x24.org> In-Reply-To: <20170107014452.9657-1-e@80x24.org> References: <20170107014452.9657-1-e@80x24.org> List-Id: This is faster, smaller, and more straighforward to me with fewer layers of indirection. --- lib/PublicInbox/Inbox.pm | 3 ++- lib/PublicInbox/Search.pm | 2 +- lib/PublicInbox/SearchIdx.pm | 4 ++-- lib/PublicInbox/SearchMsg.pm | 33 ++------------------------------- 4 files changed, 7 insertions(+), 35 deletions(-) diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index f77944f..aa4e141 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -216,7 +216,8 @@ sub msg_by_smsg ($$;$) { # backwards compat to fallback to msg_by_mid # TODO: remove if we bump SCHEMA_VERSION in Search.pm: - defined(my $blob = $smsg->blob) or return msg_by_mid($self, $smsg->mid); + defined(my $blob = $smsg->{blob}) or + return msg_by_mid($self, $smsg->mid); my $str = git($self)->cat_file($blob, $ref); $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str; diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index b59430d..86354b5 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -282,7 +282,7 @@ sub lookup_message { # raises on error: my $doc = $self->{xdb}->get_document($doc_id); $smsg = PublicInbox::SearchMsg->wrap($doc, $mid); - $smsg->doc_id($doc_id); + $smsg->{doc_id} = $doc_id; } $smsg; } diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 832d1cb..87ee0d4 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -155,7 +155,7 @@ sub add_message { if ($smsg) { # convert a ghost to a regular message # it will also clobber any existing regular message - $doc_id = $smsg->doc_id; + $doc_id = $smsg->{doc_id}; $old_tid = $smsg->thread_id; } $smsg = PublicInbox::SearchMsg->new($mime); @@ -289,7 +289,7 @@ sub link_message { my ($self, $smsg, $old_tid) = @_; my $doc = $smsg->{doc}; my $mid = $smsg->mid; - my $mime = $smsg->mime; + my $mime = $smsg->{mime}; my $hdr = $mime->header_obj; my $refs = $hdr->header_raw('References'); my @refs = $refs ? ($refs =~ /<([^>]+)>/g) : (); diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm index 4522eb6..5bb0077 100644 --- a/lib/PublicInbox/SearchMsg.pm +++ b/lib/PublicInbox/SearchMsg.pm @@ -103,7 +103,7 @@ sub from_name { sub ts { my ($self) = @_; - $self->{ts} ||= eval { str2time($self->mime->header('Date')) } || 0; + $self->{ts} ||= eval { str2time($self->{mime}->header('Date')) } || 0; } sub to_doc_data { @@ -146,36 +146,7 @@ sub mid ($;$) { } } -sub _extract_mid { mid_clean(mid_mime($_[0]->mime)) } - -sub blob { - my ($self, $x40) = @_; - if (defined $x40) { - $self->{blob} = $x40; - } else { - $self->{blob}; - } -} - -sub mime { - my ($self, $mime) = @_; - if (defined $mime) { - $self->{mime} = $mime; - } else { - # TODO load from git - $self->{mime}; - } -} - -sub doc_id { - my ($self, $doc_id) = @_; - if (defined $doc_id) { - $self->{doc_id} = $doc_id; - } else { - # TODO load from xapian - $self->{doc_id}; - } -} +sub _extract_mid { mid_clean(mid_mime($_[0]->{mime})) } sub thread_id { my ($self) = @_; -- EW