user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 03/11] nntp: remove more() wrapper
Date: Sat, 23 Jul 2022 04:41:47 +0000	[thread overview]
Message-ID: <20220723044155.3733949-4-e@80x24.org> (raw)
In-Reply-To: <20220723044155.3733949-1-e@80x24.org>

Using PublicInbox::DS->msg_more directly can avoid unnecessary
CoW memory traffic since there's no appending "\r\n".
---
 lib/PublicInbox/NNTP.pm | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 1f9058ca..e4ca7d14 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -117,7 +117,7 @@ sub cmd_slave ($) { '202 slave status noted' }
 
 sub cmd_xgtitle ($;$) {
 	my ($self, $wildmat) = @_;
-	more($self, '282 list of groups and descriptions follows');
+	$self->msg_more("282 list of groups and descriptions follows\r\n");
 	list_newsgroups($self, $wildmat);
 }
 
@@ -150,7 +150,7 @@ sub list_active_times_i {
 	for my $ngname (@window) {
 		my $ibx = $groups->{$ngname} or next;
 		my $c = eval { $ibx->uidvalidity } // time;
-		more($self, "$ngname $c <$ibx->{-primary_address}>");
+		$self->msg_more("$ngname $c <$ibx->{-primary_address}>\r\n");
 	}
 	scalar(@$groupnames); # continue if there's more
 }
@@ -169,7 +169,7 @@ sub list_newsgroups_i {
 	my $ibx;
 	for my $ngname (@window) {
 		$ibx = $groups->{$ngname} and
-			more($self, "$ngname ".$ibx->description);
+			$self->msg_more("$ngname ".$ibx->description."\r\n");
 	}
 	scalar(@$groupnames); # continue if there's more
 }
@@ -191,10 +191,10 @@ sub cmd_list ($;$$) {
 		$arg = "list_$arg";
 		$arg = $self->can($arg);
 		return r501 unless $arg && args_ok($arg, scalar @args);
-		more($self, '215 information follows');
+		$self->msg_more("215 information follows\r\n");
 		$arg->($self, @args);
 	} else {
-		more($self, '215 list of newsgroups follows');
+		$self->msg_more("215 list of newsgroups follows\r\n");
 		long_response($self, \&list_active_i, [ # copy array
 			@{$self->{nntpd}->{groupnames}} ]);
 	}
@@ -212,7 +212,7 @@ sub listgroup_all_i {
 	my ($self, $num) = @_;
 	my $ary = $self->{ibx}->over(1)->ids_after($num);
 	scalar(@$ary) or return;
-	more($self, join("\r\n", @$ary));
+	$self->msg_more(join("\r\n", @$ary, ''));
 	1;
 }
 
@@ -221,7 +221,7 @@ sub cmd_listgroup ($;$$) {
 	if (defined $group) {
 		my $res = cmd_group($self, $group);
 		return $res if ($res !~ /\A211 /);
-		more($self, $res);
+		$self->msg_more($res .= "\r\n");
 	}
 	$self->{ibx} or return '412 no newsgroup selected';
 	if (defined $range) {
@@ -262,7 +262,7 @@ sub parse_time ($$;$) {
 sub group_line ($$) {
 	my ($self, $ibx) = @_;
 	my ($min, $max) = $ibx->mm(1)->minmax;
-	more($self, "$ibx->{newsgroup} $max $min n");
+	$self->msg_more("$ibx->{newsgroup} $max $min n\r\n");
 }
 
 sub newgroups_i {
@@ -284,7 +284,7 @@ sub cmd_newgroups ($$$;$$) {
 	return r501 if $@;
 
 	# TODO dists
-	more($self, '231 list of new newsgroups follows');
+	$self->msg_more("231 list of new newsgroups follows\r\n");
 	long_response($self, \&newgroups_i, $ts, \(my $i = 0),
 				$self->{nntpd}->{groupnames});
 }
@@ -348,7 +348,7 @@ sub cmd_newnews ($$$$;$$) {
 	my ($self, $newsgroups, $date, $time, $gmt, $dists) = @_;
 	my $ts = eval { parse_time($date, $time, $gmt) };
 	return r501 if $@;
-	more($self, '230 list of new articles by message-id follows');
+	$self->msg_more("230 list of new articles by message-id follows\r\n");
 	my ($keep, $skip) = split(/!/, $newsgroups, 2);
 	ngpat2re($keep);
 	ngpat2re($skip);
@@ -565,15 +565,15 @@ sub blob_cb { # called by git->cat_async via ibx_async_cat
 	my $r = "$code $smsg->{num} <$smsg->{mid}> article retrieved - ";
 	my $eml = PublicInbox::Eml->new($bref);
 	if ($code == 220) {
-		more($self, $r .= 'head and body follow');
+		$self->msg_more($r .= "head and body follow\r\n");
 		msg_hdr_write($eml, $smsg);
 		$self->msg_more("\r\n");
 		msg_body_write($self, $bref);
 	} elsif ($code == 221) {
-		more($self, $r .= 'head follows');
+		$self->msg_more($r .= "head follows\r\n");
 		msg_hdr_write($eml, $smsg);
 	} elsif ($code == 222) {
-		more($self, $r .= 'body follows');
+		$self->msg_more($r .= "body follows\r\n");
 		msg_body_write($self, $bref);
 	} else {
 		$self->close;
@@ -609,7 +609,7 @@ sub cmd_date ($) { '111 '.strftime('%Y%m%d%H%M%S', gmtime(time)) }
 
 sub cmd_help ($) {
 	my ($self) = @_;
-	more($self, '100 help text follows');
+	$self->msg_more("100 help text follows\r\n");
 	'.'
 }
 
@@ -876,7 +876,7 @@ sub hdr_mid_response ($$$$$$) {
 sub xrover_i {
 	my ($self, $beg, $end) = @_;
 	my $h = over_header_for($self->{ibx}, $$beg, 'references');
-	more($self, "$$beg $h") if defined($h);
+	$self->msg_more("$$beg $h\r\n") if defined($h);
 	$$beg++ < $end;
 }
 
@@ -889,7 +889,7 @@ sub cmd_xrover ($;$) {
 	$range = $self->{article} unless defined $range;
 	my $r = get_range($self, $range);
 	return $r unless ref $r;
-	more($self, '224 Overview information follows');
+	$self->msg_more("224 Overview information follows\r\n");
 	long_response($self, \&xrover_i, @$r);
 }
 
@@ -916,7 +916,8 @@ sub cmd_over ($;$) {
 		my ($ibx, $n) = mid_lookup($self, $1);
 		defined $n or return r430;
 		my $smsg = $ibx->over(1)->get_art($n) or return r430;
-		more($self, '224 Overview information follows (multi-line)');
+		$self->msg_more(
+			"224 Overview information follows (multi-line)\r\n");
 
 		# Only set article number column if it's the current group
 		# (RFC 3977 8.3.2)
@@ -952,7 +953,8 @@ sub cmd_xover ($;$) {
 	my $r = get_range($self, $range);
 	return $r unless ref $r;
 	my ($beg, $end) = @$r;
-	more($self, "224 Overview information follows for $$beg to $end");
+	$self->msg_more(
+		"224 Overview information follows for $$beg to $end\r\n");
 	long_response($self, \&xover_i, @$r);
 }
 
@@ -1014,8 +1016,6 @@ sub cmd_xpath ($$) {
 
 sub res ($$) { do_write($_[0], $_[1] . "\r\n") }
 
-sub more ($$) { $_[0]->msg_more($_[1] . "\r\n") }
-
 sub do_write ($$) {
 	my $self = $_[0];
 	my $done = $self->write(\($_[1]));

  parent reply	other threads:[~2022-07-23  4:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-23  4:41 [PATCH 00/11] IMAP, NNTP, POP3 golfing Eric Wong
2022-07-23  4:41 ` [PATCH 01/11] nntp: pass regexp to split() callers Eric Wong
2022-07-23  4:41 ` [PATCH 02/11] nntp: start adding CRLF to responses natively Eric Wong
2022-07-23  4:41 ` Eric Wong [this message]
2022-07-23  4:41 ` [PATCH 04/11] ds: support greeting protocols Eric Wong
2022-07-23  4:41 ` [PATCH 05/11] ds: move no-op ->zflush to common base class Eric Wong
2022-07-23  4:41 ` [PATCH 06/11] ds: move requeue_once Eric Wong
2022-07-23  4:41 ` [PATCH 07/11] nntp: listgroup_range_i: remove useless `map' op Eric Wong
2022-07-23  4:41 ` [PATCH 08/11] nntp: inline CRLF in all response lines Eric Wong
2022-07-23  4:41 ` [PATCH 09/11] ds: share long_step between NNTP and IMAP Eric Wong
2022-07-23  4:41 ` [PATCH 10/11] nntp: resolve inboxes immediately on group listings Eric Wong
2022-07-23  4:41 ` [PATCH 11/11] imap+nntp: share COMPRESS implementation Eric Wong

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

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220723044155.3733949-4-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).