From 04248d7d4b23fdd5622265402599f1f4c5aa4744 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Mon, 5 Dec 2016 18:57:05 +0900
Subject: [PATCH 2/2] Several trivial fixes on convutils.pm

---
 src/backend/utils/mb/Unicode/convutils.pm | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/backend/utils/mb/Unicode/convutils.pm b/src/backend/utils/mb/Unicode/convutils.pm
index 30227fe..a5644a0 100644
--- a/src/backend/utils/mb/Unicode/convutils.pm
+++ b/src/backend/utils/mb/Unicode/convutils.pm
@@ -5,8 +5,6 @@
 
 use strict;
 
-use Data::Dumper;
-
 #######################################################################
 # convert UCS-4 to UTF-8
 #
@@ -376,7 +374,7 @@ sub print_radix_table
 	### Build a linear list of "segments", from the nested hashes.
 	###
 	### Each segment is a lookup table, keyed by the next byte in the input.
-	### The segments are written out physically to one big array in the final,
+	### The segments are written out physically to one big array in the final
 	### step, but logically, they form a radix tree. Or rather, four radix
 	### trees: one for 1-byte inputs, another for 2-byte inputs, 3-byte
 	### inputs, and 4-byte inputs.
@@ -415,14 +413,10 @@ sub print_radix_table
 		my $this_min = $min_idx{$seg->{depth}}->{$seg->{level}};
 		my $this_max = $max_idx{$seg->{depth}}->{$seg->{level}};
 
-		for (my $i=0; $i <= 0xff; $i++)
+		foreach my $i (keys $seg->{values})
 		{
-			my $val = $seg->{values}->{$i};
-			if ($val)
-			{
-				$this_min = $i if (!defined $this_min || $i < $this_min);
-				$this_max = $i if (!defined $this_max || $i > $this_max);
-			}
+			$this_min = $i if (!defined $this_min || $i < $this_min);
+			$this_max = $i if (!defined $this_max || $i > $this_max);
 		}
 
 		$min_idx{$seg->{depth}}{$seg->{level}} = $this_min;
@@ -517,10 +511,9 @@ sub print_radix_table
 	# Second pass: look up the offset of each label reference in the hash.
 	foreach my $seg (@segments)
 	{
-		for (my $i=0; $i <= 0xff; $i++)
+		while (my ($i, $val) = each %{$seg->{values}})
 		{
-			my $val = $seg->{values}->{$i};
-			if ($val && !($val =~ /^[0-9,.E]+$/ ))
+			if (!($val =~ /^[0-9,.E]+$/ ))
 			{
 				my $segoff = $segmap{$val};
 				if ($segoff)
@@ -573,9 +566,8 @@ sub print_radix_table
 	my $max_val = 0;
 	foreach my $seg (@segments)
 	{
-		for (my $i=0; $i <= 0xFF ; $i++)
+		foreach my $val (values $seg->{values})
 		{
-			my $val = $seg->{values}->{$i};
 			$max_val = $val if ($val > $max_val);
 		}
 	}
@@ -729,15 +721,13 @@ sub build_segments_recurse
 	{
 		my %children;
 
-		for (my $i=0; $i <= 0xff; $i++)
+		while (my ($i, $val) = each $map)
 		{
-			next if (!$map->{$i});
-
 			my $childpath = $path . sprintf("%02x", $i);
 			my $childlabel = "$depth-level-$level-$childpath";
 
 			push @segments, build_segments_recurse($header, $childlabel, $childpath,
-												   $level + 1, $depth, $map->{$i});
+												   $level + 1, $depth, $val);
 			$children{$i} = $childlabel;
 		}
 
-- 
2.9.2

