New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Cwd.pm, dont repeatedly access magic %ENV vars #14825
Comments
From @bulk88Created by @bulk88See attached patch. Perl Info
|
From @bulk880001-Cwd.pm-dont-repeatedly-access-magic-ENV-vars.patchFrom f6c71435312084daaa30ecc092ad3853980634a5 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Tue, 28 Jul 2015 23:08:38 -0400
Subject: [PATCH] Cwd.pm, dont repeatedly access magic %ENV vars
%ENV is magic/tied, a lexical is faster than calling out to magic APIs
with gets and sets (or checks for them). Less glob and hash lookups too.
Return the lexical instead of the magic var so there isn't a search for
magic from pp_leavesub's sv_mortalcopy. Even though env mg vtable doesn't
have a getter or GMAGIC, SvVSTRING_mg executes mg_find for random, get
and set magic inside Perl_sv_setsv_flags.
---
dist/PathTools/Cwd.pm | 51 ++++++++++++++++++++++++++----------------------
1 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/dist/PathTools/Cwd.pm b/dist/PathTools/Cwd.pm
index 49cc4c1..0765de4 100644
--- a/dist/PathTools/Cwd.pm
+++ b/dist/PathTools/Cwd.pm
@@ -3,7 +3,7 @@ use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
-$VERSION = '3.56';
+$VERSION = '3.57';
my $xs_version = $VERSION;
$VERSION =~ tr/_//;
@@ -600,20 +600,23 @@ sub _vms_abs_path {
}
sub _os2_cwd {
- $ENV{'PWD'} = `cmd /c cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ my $pwd = `cmd /c cd`;
+ chomp $pwd;
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _win32_cwd_simple {
- $ENV{'PWD'} = `cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ my $pwd = `cd`;
+ chomp $pwd;
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _win32_cwd {
+ my $pwd;
# Need to avoid taking any sort of reference to the typeglob or the code in
# the optree, so that this tests the runtime state of things, as the
# ExtUtils::MakeMaker tests for "miniperl" need to be able to fake things at
@@ -622,35 +625,38 @@ sub _win32_cwd {
# problems (for reasons that we haven't been able to get to the bottom of -
# rt.cpan.org #56225)
if (*{$DynaLoader::{boot_DynaLoader}}{CODE}) {
- $ENV{'PWD'} = Win32::GetCwd();
+ $pwd = Win32::GetCwd();
}
else { # miniperl
- chomp($ENV{'PWD'} = `cd`);
+ chomp($pwd = `cd`);
}
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
*_NT_cwd = defined &Win32::GetCwd ? \&_win32_cwd : \&_win32_cwd_simple;
sub _dos_cwd {
+ my $pwd;
if (!defined &Dos::GetCwd) {
- $ENV{'PWD'} = `command /c cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
+ chomp($pwd = `command /c cd`);
+ $pwd =~ s:\\:/:g ;
} else {
- $ENV{'PWD'} = Dos::GetCwd();
+ $pwd = Dos::GetCwd();
}
- return $ENV{'PWD'};
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _qnx_cwd {
local $ENV{PATH} = '';
local $ENV{CDPATH} = '';
local $ENV{ENV} = '';
- $ENV{'PWD'} = `/usr/bin/fullpath -t`;
- chomp $ENV{'PWD'};
- return $ENV{'PWD'};
+ my $pwd = `/usr/bin/fullpath -t`;
+ chomp $pwd;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _qnx_abs_path {
@@ -669,8 +675,7 @@ sub _qnx_abs_path {
}
sub _epoc_cwd {
- $ENV{'PWD'} = EPOC::getcwd();
- return $ENV{'PWD'};
+ return $ENV{'PWD'} = EPOC::getcwd();
}
--
1.7.9.msysgit.0
|
From @bulk88On Tue Jul 28 21:24:24 2015, bulk88 wrote:
First patch had test failures due to incorrect version bumping. New attached. -- |
From @bulk880001-Cwd.pm-dont-repeatedly-access-magic-ENV-vars.patchFrom fd9b3bec5abe588e5799e86968f834da44a84320 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Wed, 29 Jul 2015 09:54:51 -0400
Subject: [PATCH] Cwd.pm, dont repeatedly access magic %ENV vars
%ENV is magic/tied, a lexical is faster than calling out to magic APIs
with gets and sets (or checks for them). Less glob and hash lookups too.
Return the lexical instead of the magic var so there isn't a search for
magic from pp_leavesub's sv_mortalcopy. Even though env mg vtable doesn't
have a getter or GMAGIC, SvVSTRING_mg executes mg_find for random, get
and set magic inside Perl_sv_setsv_flags.
---
dist/PathTools/Cwd.pm | 51 ++++++++++++++++-------------
dist/PathTools/lib/File/Spec.pm | 2 +-
dist/PathTools/lib/File/Spec/Cygwin.pm | 2 +-
dist/PathTools/lib/File/Spec/Epoc.pm | 2 +-
dist/PathTools/lib/File/Spec/Functions.pm | 2 +-
dist/PathTools/lib/File/Spec/Mac.pm | 2 +-
dist/PathTools/lib/File/Spec/OS2.pm | 2 +-
dist/PathTools/lib/File/Spec/Unix.pm | 2 +-
dist/PathTools/lib/File/Spec/VMS.pm | 2 +-
dist/PathTools/lib/File/Spec/Win32.pm | 2 +-
10 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/dist/PathTools/Cwd.pm b/dist/PathTools/Cwd.pm
index 49cc4c1..0765de4 100644
--- a/dist/PathTools/Cwd.pm
+++ b/dist/PathTools/Cwd.pm
@@ -3,7 +3,7 @@ use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
-$VERSION = '3.56';
+$VERSION = '3.57';
my $xs_version = $VERSION;
$VERSION =~ tr/_//;
@@ -600,20 +600,23 @@ sub _vms_abs_path {
}
sub _os2_cwd {
- $ENV{'PWD'} = `cmd /c cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ my $pwd = `cmd /c cd`;
+ chomp $pwd;
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _win32_cwd_simple {
- $ENV{'PWD'} = `cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ my $pwd = `cd`;
+ chomp $pwd;
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _win32_cwd {
+ my $pwd;
# Need to avoid taking any sort of reference to the typeglob or the code in
# the optree, so that this tests the runtime state of things, as the
# ExtUtils::MakeMaker tests for "miniperl" need to be able to fake things at
@@ -622,35 +625,38 @@ sub _win32_cwd {
# problems (for reasons that we haven't been able to get to the bottom of -
# rt.cpan.org #56225)
if (*{$DynaLoader::{boot_DynaLoader}}{CODE}) {
- $ENV{'PWD'} = Win32::GetCwd();
+ $pwd = Win32::GetCwd();
}
else { # miniperl
- chomp($ENV{'PWD'} = `cd`);
+ chomp($pwd = `cd`);
}
- $ENV{'PWD'} =~ s:\\:/:g ;
- return $ENV{'PWD'};
+ $pwd =~ s:\\:/:g ;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
*_NT_cwd = defined &Win32::GetCwd ? \&_win32_cwd : \&_win32_cwd_simple;
sub _dos_cwd {
+ my $pwd;
if (!defined &Dos::GetCwd) {
- $ENV{'PWD'} = `command /c cd`;
- chomp $ENV{'PWD'};
- $ENV{'PWD'} =~ s:\\:/:g ;
+ chomp($pwd = `command /c cd`);
+ $pwd =~ s:\\:/:g ;
} else {
- $ENV{'PWD'} = Dos::GetCwd();
+ $pwd = Dos::GetCwd();
}
- return $ENV{'PWD'};
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _qnx_cwd {
local $ENV{PATH} = '';
local $ENV{CDPATH} = '';
local $ENV{ENV} = '';
- $ENV{'PWD'} = `/usr/bin/fullpath -t`;
- chomp $ENV{'PWD'};
- return $ENV{'PWD'};
+ my $pwd = `/usr/bin/fullpath -t`;
+ chomp $pwd;
+ $ENV{'PWD'} = $pwd;
+ return $pwd;
}
sub _qnx_abs_path {
@@ -669,8 +675,7 @@ sub _qnx_abs_path {
}
sub _epoc_cwd {
- $ENV{'PWD'} = EPOC::getcwd();
- return $ENV{'PWD'};
+ return $ENV{'PWD'} = EPOC::getcwd();
}
diff --git a/dist/PathTools/lib/File/Spec.pm b/dist/PathTools/lib/File/Spec.pm
index 8c77c98..2f35526 100644
--- a/dist/PathTools/lib/File/Spec.pm
+++ b/dist/PathTools/lib/File/Spec.pm
@@ -3,7 +3,7 @@ package File::Spec;
use strict;
use vars qw(@ISA $VERSION);
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
my %module = (MacOS => 'Mac',
diff --git a/dist/PathTools/lib/File/Spec/Cygwin.pm b/dist/PathTools/lib/File/Spec/Cygwin.pm
index 1b77e6a..e5839e9 100644
--- a/dist/PathTools/lib/File/Spec/Cygwin.pm
+++ b/dist/PathTools/lib/File/Spec/Cygwin.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw(@ISA $VERSION);
require File::Spec::Unix;
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
@ISA = qw(File::Spec::Unix);
diff --git a/dist/PathTools/lib/File/Spec/Epoc.pm b/dist/PathTools/lib/File/Spec/Epoc.pm
index 7bc3867..390a641 100644
--- a/dist/PathTools/lib/File/Spec/Epoc.pm
+++ b/dist/PathTools/lib/File/Spec/Epoc.pm
@@ -3,7 +3,7 @@ package File::Spec::Epoc;
use strict;
use vars qw($VERSION @ISA);
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
require File::Spec::Unix;
diff --git a/dist/PathTools/lib/File/Spec/Functions.pm b/dist/PathTools/lib/File/Spec/Functions.pm
index 8eafe24..5c2cec0 100644
--- a/dist/PathTools/lib/File/Spec/Functions.pm
+++ b/dist/PathTools/lib/File/Spec/Functions.pm
@@ -5,7 +5,7 @@ use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
require Exporter;
diff --git a/dist/PathTools/lib/File/Spec/Mac.pm b/dist/PathTools/lib/File/Spec/Mac.pm
index 02cae14..7cc816f 100644
--- a/dist/PathTools/lib/File/Spec/Mac.pm
+++ b/dist/PathTools/lib/File/Spec/Mac.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw(@ISA $VERSION);
require File::Spec::Unix;
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
@ISA = qw(File::Spec::Unix);
diff --git a/dist/PathTools/lib/File/Spec/OS2.pm b/dist/PathTools/lib/File/Spec/OS2.pm
index fb8f101..8d3951f 100644
--- a/dist/PathTools/lib/File/Spec/OS2.pm
+++ b/dist/PathTools/lib/File/Spec/OS2.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw(@ISA $VERSION);
require File::Spec::Unix;
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
@ISA = qw(File::Spec::Unix);
diff --git a/dist/PathTools/lib/File/Spec/Unix.pm b/dist/PathTools/lib/File/Spec/Unix.pm
index f76b29e..48e2b60 100644
--- a/dist/PathTools/lib/File/Spec/Unix.pm
+++ b/dist/PathTools/lib/File/Spec/Unix.pm
@@ -3,7 +3,7 @@ package File::Spec::Unix;
use strict;
use vars qw($VERSION);
-$VERSION = '3.56';
+$VERSION = '3.57';
my $xs_version = $VERSION;
$VERSION =~ tr/_//;
diff --git a/dist/PathTools/lib/File/Spec/VMS.pm b/dist/PathTools/lib/File/Spec/VMS.pm
index 254f524..5e4a3b3 100644
--- a/dist/PathTools/lib/File/Spec/VMS.pm
+++ b/dist/PathTools/lib/File/Spec/VMS.pm
@@ -4,7 +4,7 @@ use strict;
use vars qw(@ISA $VERSION);
require File::Spec::Unix;
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
@ISA = qw(File::Spec::Unix);
diff --git a/dist/PathTools/lib/File/Spec/Win32.pm b/dist/PathTools/lib/File/Spec/Win32.pm
index 53f3854..77e0fed 100644
--- a/dist/PathTools/lib/File/Spec/Win32.pm
+++ b/dist/PathTools/lib/File/Spec/Win32.pm
@@ -5,7 +5,7 @@ use strict;
use vars qw(@ISA $VERSION);
require File::Spec::Unix;
-$VERSION = '3.56';
+$VERSION = '3.57';
$VERSION =~ tr/_//;
@ISA = qw(File::Spec::Unix);
--
1.7.9.msysgit.0
|
From @tonycozOn Wed Jul 29 08:20:08 2015, bulk88 wrote:
Thanks, applied as 3480fba. Tony |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'resolved' |
From wuhaoecho@gmail.comsince you change - $ENV{'PWD'} = EPOC::getcwd(); why not change all + $ENV{'PWD'} = $pwd; to return $ENV{'PWD'} = $pwd; ? although there should not be much difference. Best, Hao On Wed, Jul 29, 2015 at 8:20 AM, bulk88 via RT <perlbug-followup@perl.org>
|
From @bulk88On Thu Jul 30 16:09:24 2015, wuhaoecho@gmail.com wrote:
sub _epoc_cwd { to sub _epoc_cwd { makes no sense. sub _epoc_cwd { has 2 extra nextstate ops. one lvalue_intro op for the my line. 1 extra assignment op. 3 extra pad fetch ops. I didnt benchmark it, but I dont see that many extra ops being faster than scanning the linked list for magic. In the other subs, $pwd was read and written to in each line and there were multiple lines. In the epoc version there was no modifying, and only one line. Read the commit message, I'll repost the relevant part. Return the lexical instead of the magic var so there isn't a search for magic from pp_leavesub's sv_mortalcopy. Even though env mg vtable doesn't have a getter or GMAGIC, SvVSTRING_mg executes mg_find for random, get and set magic inside Perl_sv_setsv_flags. -- |
Migrated from rt.perl.org#125712 (status was 'resolved')
Searchable as RT125712$
The text was updated successfully, but these errors were encountered: