From c8e55bd9ff36029c3f4fe7053f54f9f862c79d7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Mon, 17 Apr 2017 14:47:06 +0100
Subject: [PATCH 3/8] Inline SplitDataLines into its only caller

---
 src/backend/catalog/Catalog.pm | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index 0c508b0..9bd6263 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -82,12 +82,24 @@ sub Catalogs
 			}
 			elsif (/^DATA\(insert(?:\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/)
 			{
-				my @bki_values = SplitDataLine($2);
+				# The field-splitting regex will clobber $1, save it
+				my $oid = $1;
+
+				# This handling of quoted strings might look too
+				# simplistic, but it matches what bootscanner.l does:
+				# that has no provision for quote marks inside quoted
+				# strings, either.  If we don't have a quoted string,
+				# just snarf everything till next whitespace.  That will
+				# accept some things that bootscanner.l will see as
+				# erroneous tokens; but it seems wiser to do that and
+				# let bootscanner.l complain than to silently drop
+				# non-whitespace characters.
+				my @bki_values = $2 =~ /"[^"]*"|\S+/g;
 
 				check_natts($filename, $catalog{natts}, scalar(@bki_values),
 							$input_file, $input_line_number);
 
-				push @{ $catalog{data} }, { oid => $1, bki_values => \@bki_values };
+				push @{ $catalog{data} }, { oid => $oid, bki_values => \@bki_values };
 			}
 			elsif (/^DESCR\(\"(.*)\"\)$/)
 			{
@@ -218,28 +230,6 @@ sub Catalogs
 	return \%catalogs;
 }
 
-# Split a DATA line into fields.
-# Call this on the bki_values element of a DATA item returned by Catalogs();
-# it returns a list of field values.  We don't strip quoting from the fields.
-# Note: it should be safe to assign the result to a list of length equal to
-# the nominal number of catalog fields, because check_natts already checked
-# the number of fields.
-sub SplitDataLine
-{
-	my $bki_values = shift;
-
-	# This handling of quoted strings might look too simplistic, but it
-	# matches what bootscanner.l does: that has no provision for quote marks
-	# inside quoted strings, either.  If we don't have a quoted string, just
-	# snarf everything till next whitespace.  That will accept some things
-	# that bootscanner.l will see as erroneous tokens; but it seems wiser
-	# to do that and let bootscanner.l complain than to silently drop
-	# non-whitespace characters.
-	my @result = $bki_values =~ /"[^"]*"|\S+/g;
-
-	return @result;
-}
-
 # Rename temporary files to final names.
 # Call this function with the final file name and the .tmp extension
 # Note: recommended extension is ".tmp$$", so that parallel make steps
-- 
2.7.4

