TT#69200 Use sprintf instead of ad-hoc code to 0 fill digits

Which is also around 300% faster:

                Rate had-hoc sprintf
  had-hoc  3508772/s      --    -75%
  sprintf 14084507/s    301%      --

Change-Id: I5ebce0058473f9de08c381739646a20e42308a8f
(cherry picked from commit 561e36d08c)
mr7.5.5
Guillem Jover 6 years ago committed by Rene Krenn
parent 02d0d69f21
commit e49f5fbb33

7
debian/control vendored

@ -4,7 +4,14 @@ Priority: optional
Maintainer: Sipwise Development Team <support@sipwise.com>
Build-Depends:
debhelper-compat (= 12),
libdata-uuid-perl <!nocheck>,
libdata-validate-ip-perl <!nocheck>,
libdate-calc-perl <!nocheck>,
libdate-manip-perl <!nocheck>,
libmodule-build-perl,
libnet-address-ip-local-perl <!nocheck>,
libsys-cpuaffinity-perl <!nocheck>,
libuuid-perl <!nocheck>,
Standards-Version: 3.9.8
Homepage: https://www.sipwise.com/

@ -440,14 +440,8 @@ sub get_year_month_day {
sub zerofill {
my ($integer,$digits) = @_;
my $numberofzeroes = $digits - length($integer);
my $resultstring = $integer;
if ($digits > 0) {
for (my $i = 0; $i < $numberofzeroes; $i += 1) {
$resultstring = "0" . $resultstring;
}
}
return $resultstring;
return sprintf '%0*d', $digits, $integer;
}
sub trim {

@ -0,0 +1,30 @@
#!/usr/bin/perl
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use warnings;
use Test::More tests => 4;
require_ok('NGCP::BulkProcessor::Utils');
NGCP::BulkProcessor::Utils->import(qw(
zerofill
));
# zerofill()
is(zerofill(0, 4), '0000');
is(zerofill(25, 4), '0025');
is(zerofill(1000, 4), '1000');
Loading…
Cancel
Save