Subject: | speed up header folding |
This is a small but notable increase in the speed of header folding. Patches attached.
--
rjbs
Subject: | 0001-linewrap-tests-add-a-stronger-assertion-about-expect.patch |
From 4ff4a7b5d2b25c04657b98b124e40d4232e48132 Mon Sep 17 00:00:00 2001
From: Ricardo Signes <rjbs@cpan.org>
Date: Tue, 13 Aug 2019 11:01:28 -0400
Subject: [PATCH 1/2] linewrap tests: add a stronger assertion about
expectation
---
t/02.linewrap.t | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/t/02.linewrap.t b/t/02.linewrap.t
index 4f657c4..01018a3 100644
--- a/t/02.linewrap.t
+++ b/t/02.linewrap.t
@@ -21,5 +21,18 @@ $todo->add_property(summary => $hundreds_of_characters);
lacks_string($todo->as_string, $hundreds_of_characters, "the long string isn't there");
unlike_string($todo->as_string, qr/[^\r\n]{76}/, "no lines are too long");
+my $want = <<'END';
+BEGIN:VTODO
+SUMMARY:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ XXXXXXXXXXX
+END:VTODO
+END
+
+$want =~ s/\n/\r\n/g;
+
+is($todo->as_string, $want, "expectations: met");
like_string($todo->as_string(fold => 0), qr/.{300}/, "no lines are too long".$todo->as_string(fold=>0));
--
2.21.0
Subject: | 0002-rewrite-property-folding-to-be-faster-and-clearer.patch |
From eafa30d1b3acf90c0e71a3522f7730a21104fe88 Mon Sep 17 00:00:00 2001
From: Calvin Morrison <calvin@fastmailteam.com>
Date: Tue, 13 Aug 2019 11:01:58 -0400
Subject: [PATCH 2/2] rewrite property folding to be faster (and clearer)
---
lib/Data/ICal/Property.pm | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/lib/Data/ICal/Property.pm b/lib/Data/ICal/Property.pm
index 1617927..6acfd6a 100644
--- a/lib/Data/ICal/Property.pm
+++ b/lib/Data/ICal/Property.pm
@@ -326,15 +326,18 @@ sub _fold {
# But some interop tests suggest it's wiser just to not fold for vcal 1.0
# at all (in quoted-printable).
} else {
- my $pos = 0;
-
- # Walk through the value, looking to replace 75 characters at
- # a time. We assign to pos() to update where to pick up for
- # the next match.
- while ( $string =~ s/\G(.{75})(?=.)/$1$crlf / ) {
- $pos += 75 + length($crlf);
- pos($string) = $pos;
+ return $string unless length $string > 75;
+
+ $string =~ s{$crlf\z}{};
+
+ my $out = substr($string, 0, 75, "") . $crlf;
+
+ while (length $string) {
+ my $substr = substr $string, 0, 74, "";
+ $out .= " $substr$crlf";
}
+
+ return $out;
}
return $string;
--
2.21.0