Inliner.pm

filter: Statementstmt 100% 18 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod 0.0% 0 / 1 totaltotal 95.0% 19 / 20 CC 1 SCAR 0.0
CC
1
Cov
100%
inline
1.0
CRAP 1.0
« ZConst.pm ↑ Summary Quetzal.pm »
1 package Games::Rezrov::Inliner;
2  
3 # inline a few of the most frequently used z-machine memory access
4 # calls. Provides a speed improvement at the cost of more obfuscated
5 # and heinously non-OO code. Oh well.
6  
7 # only works for TRIVIAL code: will break if "arguments" for inlined
8 # routines contain parens (can't handle nesting)
9  
10 1 1;
11  
12 8 ▶sub inline {
Subroutine inline: called CC=1 SCAR=0.0
Pod undocumented
13 8 my $ref = shift;
14
15 8 my $rep = 'vec($Games::Rezrov::StoryFile::STORY_BYTES, $Games::Rezrov::StoryFile::PC++, 8)';
16 8 $$ref =~ s/GET_BYTE\(\)/$rep/og;
17 # replaces StoryFile::get_byte() -- z-machine memory access
18
19 8 $rep = '(vec($Games::Rezrov::StoryFile::STORY_BYTES, $Games::Rezrov::StoryFile::PC++, 8) << 8) + vec($Games::Rezrov::StoryFile::STORY_BYTES, $Games::Rezrov::StoryFile::PC++, 8)';
20 8 $$ref =~ s/GET_WORD\(\)/$rep/og;
21 # replaces StoryFile::get_word() -- z-machine memory access
22  
23 8 $rep = 'unpack("S", pack("s", %s))';
24 8 $$ref =~ s/UNSIGNED_WORD\((.*?)\)/sprintf $rep, $1/eog;
25 # cast a perl variable into a unsigned 16-bit word (short).
26 # Necessary to ensure the sign bit is placed at 0x8000.
27 # Replaces unsigned_word() subroutine.
28 # WILL ONLY WORK IF NO NESTED PARENS
29  
30 8 $rep = 'unpack("s", pack("s", %s))';
31 8 $$ref =~ s/SIGNED_WORD\((.*?)\)/sprintf $rep, $1/eog;
32 # cast a perl variable into a signed 16-bit word (short).
33 # replaces signed_word() subroutine.
34 # WILL ONLY WORK IF NO NESTED PARENS
35  
36 8 $rep = 'vec($Games::Rezrov::StoryFile::STORY_BYTES, %s, 8)';
37 8 $$ref =~ s/GET_BYTE_AT\((.*?)\)/sprintf $rep, $1/eog;
38 # replaces StoryFile::get_byte_at($x) -- memory access
39 # WILL ONLY WORK IF NO NESTED PARENS
40  
41 8 $rep = '(vec($Games::Rezrov::StoryFile::STORY_BYTES, %s, 8) << 8) + vec($Games::Rezrov::StoryFile::STORY_BYTES, %s + 1, 8)';
42 8 $$ref =~ s/GET_WORD_AT\((.*?)\)/sprintf $rep, $1, $1/eog;
43 # replaces StoryFile::get_word_at($x) -- memory access
44 # WILL ONLY WORK IF NO NESTED PARENS
45
46 }
« ZConst.pm ↑ Summary Quetzal.pm »