Skip to content
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

Optimisation of split #13909

Open
p5pRT opened this issue Jun 8, 2014 · 3 comments
Open

Optimisation of split #13909

p5pRT opened this issue Jun 8, 2014 · 3 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Jun 8, 2014

Migrated from rt.perl.org#122064 (status was 'open')

Searchable as RT122064$

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2014

From the.rob.dixon@gmail.com

This is a bug report for perl from the.rob.dixon@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.0.


I notice that

  ($x, $y) = split

is usefully optimised to

  ($x, $y) = split(' ', $_, 3)

and I wonder how hard it would be to do something similar by changing

  $x = (split)[3]

to

  $x = (split ' ', $_, 4)[3]

because at present this is most efficiently coded as the ugly

  (undef, undef, undef, $x) = split;



Flags​:
  category=core
  severity=wishlist


Site configuration information for perl 5.20.0​:

Configured by strawberry-perl at Fri May 30 23​:27​:10 2014.

Summary of my perl5 (revision 5 version 20 subversion 0) configuration​:

  Platform​:
  osname=MSWin32, osvers=6.2, archname=MSWin32-x86-multi-thread-64int
  uname='Win32 strawberry-perl 5.20.0.1 #1 Fri May 30 23​:25​:11 2014 i386'
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  useithreads=define, usemultiplicity=define
  use64bitint=define, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags =' -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv
-fno-strict-aliasing -mms-bitfields',
  optimize='-s -O2',
  cppflags='-DWIN32'
  ccversion='', gccversion='4.8.2', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='long
long', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='g++', ldflags ='-s -L"C​:\STRAWB3\perl\lib\CORE"
-L"C​:\STRAWB
3\c\lib"'
  libpth=C​:\STRAWB3\c\lib C​:\STRAWB3\c\i686-w64-mingw32\lib
C​:\STRAWB3\c\lib\gcc\i686-w64-mingw32\4.8.2
  libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  libc=, so=dll, useshrplib=true, libperl=libperl520.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=xs.dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-mdll -s -L"C​:\STRAWB
3\perl\lib\CORE"
-L"C​:\STRAWB~3\c\lib"'


@​INC for perl 5.20.0​:
  C​:/Strawberry/perl/site/lib/MSWin32-x86-multi-thread-64int
  C​:/Strawberry/perl/site/lib
  C​:/Strawberry/perl/vendor/lib
  C​:/Strawberry/perl/lib
  .


Environment for perl 5.20.0​:
  HOME (unset)
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=C​:\Program Files (x86)\ImageMagick-6.8.3-Q16;C​:\Program
Files\ImageMagick-6.8.3-Q16;C​:\Program Files (x86)\NVIDIA
Corporation\PhysX\Common;C​:\Program Files (x86)\PC Connectivity
Solution\;C​:\Program Files\Common Files\Microsoft Shared\Windows
Live;C​:\Program Files
(x86)\PHP\;C​:\Windows\system32;C​:\Windows;C​:\Windows\System32\Wbem;C​:\Windows\System32\WindowsPowerShell\v1.0\;C​:\Program
Files\jEdit;C​:\usr\local\ppt\bin;C​:\Program Files
(x86)\GnuWin32\bin;C​:\Program Files (x86)\Smart
Projects\IsoBuster;C​:\Program Files (x86)\Oracle\Berkeley DB 11gR2
5.3.15\bin;C​:\Program Files (x86)\Git\cmd;C​:\Program Files
(x86)\Bazaar;C​:\Program Files (x86)\Lua\5.1;C​:\Program Files
(x86)\Lua\5.1\clibs;C​:\Program
Files\TortoiseSVN\bin;C​:\MediaInfoCLI;C​:\Program Files
(x86)\MKVToolNix;C​:\Program Files (x86)\Subversion\bin;C​:\Program Files
(x86)\Common Files\Ulead Systems\MPEG;C​:\Program Files
(x86)\QuickTime\QTSystem\;C​:\Program Files\Microsoft Network Monitor
3\;C​:\Program Files\Calibre2\;C​:\Program Files (x86)\MySQL\MySQL Utilities
1.3.4\;C​:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C​:\Program
Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C​:\Program
Files\Microsoft SQL Server\110\Tools\Binn\;C​:\Program Files (x86)\Microsoft
SDKs\TypeScript\1.0\;C​:\Strawberry\c\bin;C​:\Strawberry\perl\site\bin;C​:\Strawberry\perl\bin;C​:\SQLite;C​:\Program
Files\WinRAR;C​:\Program Files\Common Files\Microsoft Shared\Windows
Live;C​:\Program Files (x86)\Common Files\Hackety Hack\0.r1529\..;C​:\Program
Files (x86)\IDM Computer Solutions\UltraCompare\;C​:\ffmpeg\bin;C​:\Program
Files (x86)\Serviio\lib;C​:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\bin\x86_amd64;C​:\Program Files (x86)\Microsoft Visual Studio
10.0\VC\bin\amd64;C​:\SWIG;C​:\MinGW\bin;C​:\MinGW\MSYS\1.0\bin;C​:\Python27;C​:\Curl;C​:\pkg-config\bin;C​:\glib\bin;C​:\gettext-runtime\bin;C​:\Program
Files (x86)\IDM Computer Solutions\UltraEdit\;C​:\LuaRocks\2.0;C​:\Program
Files
(x86)\Android\android-sdk\platform-tools;C​:\Ruby193\bin;C​:\Ruby193.DevKit\bin;C​:\Program
Files (x86)\Nmap;C​:\MobiPerl;E​:\Perl\source;C​:\Program Files
(x86)\EaseUS\Todo Backup\bin\x64\
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2014

From @cpansprout

On Sun Jun 08 14​:53​:33 2014, the.rob.dixon@​gmail.com wrote​:

This is a bug report for perl from the.rob.dixon@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.0.

-----------------------------------------------------------------

I notice that

($x, $y) = split

is usefully optimised to

($x, $y) = split(' ', $_, 3)

and I wonder how hard it would be to do something similar by changing

$x = (split)[3]

to

$x = (split ' ', $_, 4)[3]

because at present this is most efficiently coded as the ugly

(undef, undef, undef, $x) = split;

But adding an implicit limit changes the behaviour​:

$ perl -le 'print "[",$_//"undef","]" for (split /,/, "a,,,,,,")[3]'
$ perl -le 'print "[",$_//"undef","]" for (split /,/, "a,,,,,,", 5)[3]'
[]

And fixing the existing optimisation to be a pure optimisation is controversial. See ticket #118879.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT p5pRT added the Wishlist label Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant