]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchmsg: favor direct hash access over accessor methods
authorEric Wong <e@80x24.org>
Sat, 7 Jan 2017 01:44:51 +0000 (01:44 +0000)
committerEric Wong <e@80x24.org>
Sat, 7 Jan 2017 01:45:45 +0000 (01:45 +0000)
This is faster, smaller, and more straighforward to me with
fewer layers of indirection.

lib/PublicInbox/Inbox.pm
lib/PublicInbox/Search.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/SearchMsg.pm

index f77944f5c441b0ffa849eb84c89a9fbd7db3bc71..aa4e141f6cfcd36a67bca71893a6363b8b0005c7 100644 (file)
@@ -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;
index b59430d8e9d7748c0ad49130d22acdeeebfafaca..86354b571f88541fe2d271c92c220204a151bf97 100644 (file)
@@ -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;
 }
index 832d1cbfccc06aa3ab4e5948190b5856431bb5ac..87ee0d46406ef688aa215356143923a82ddd9b14 100644 (file)
@@ -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) : ();
index 4522eb628d5bdd49e7f9b1c725a2325af034b496..5bb00778f1472712d1d609d72bda75125fea3ad0 100644 (file)
@@ -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) = @_;