Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm |
Statements | Executed 118586 statements in 24.8s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
8 | 1 | 1 | 24.0s | 24.0s | CORE:sleep (opcode) | OCBNET::Spritesets::Canvas::Distribute::
12 | 1 | 1 | 1.47s | 30.4s | distribute | OCBNET::Spritesets::Canvas::Distribute::
48 | 4 | 1 | 50.2ms | 70.3ms | CORE:sort (opcode) | OCBNET::Spritesets::Canvas::Distribute::
168 | 1 | 1 | 8.21ms | 8.21ms | CORE:subst (opcode) | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 134µs | 237µs | BEGIN@10 | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 54µs | 86µs | BEGIN@11 | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 54µs | 54µs | BEGIN@19.5 | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 27µs | 27µs | BEGIN@22 | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 24µs | 24µs | BEGIN@19 | OCBNET::Spritesets::Canvas::Distribute::
1 | 1 | 1 | 23µs | 23µs | BEGIN@16 | OCBNET::Spritesets::Canvas::Distribute::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ################################################################################################### | ||||
2 | # Copyright 2013 by Marcel Greter | ||||
3 | # This file is part of Webmerge (GPL3) | ||||
4 | #################################################################################################### | ||||
5 | # static helper functions for canvas | ||||
6 | #################################################################################################### | ||||
7 | package OCBNET::Spritesets::Canvas::Distribute; | ||||
8 | #################################################################################################### | ||||
9 | |||||
10 | 2 | 162µs | 2 | 340µs | # spent 237µs (134+103) within OCBNET::Spritesets::Canvas::Distribute::BEGIN@10 which was called:
# once (134µs+103µs) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 10 # spent 237µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@10
# spent 103µs making 1 call to strict::import |
11 | 2 | 192µs | 2 | 118µs | # spent 86µs (54+32) within OCBNET::Spritesets::Canvas::Distribute::BEGIN@11 which was called:
# once (54µs+32µs) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 11 # spent 86µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@11
# spent 32µs making 1 call to warnings::import |
12 | |||||
13 | ################################################################################################### | ||||
14 | |||||
15 | # define our version string | ||||
16 | 1 | 141µs | 1 | 23µs | # spent 23µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@16 which was called:
# once (23µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 16 # spent 23µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@16 |
17 | |||||
18 | # load exporter and inherit from it | ||||
19 | 3 | 353µs | 2 | 77µs | # spent 54µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@19.5 which was called:
# once (54µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 19
# spent 24µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@19 which was called:
# once (24µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 19 # spent 54µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@19.5
# spent 24µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@19 |
20 | |||||
21 | # define our functions to be exported | ||||
22 | 1 | 3.60ms | 1 | 27µs | # spent 27µs within OCBNET::Spritesets::Canvas::Distribute::BEGIN@22 which was called:
# once (27µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@21 at line 22 # spent 27µs making 1 call to OCBNET::Spritesets::Canvas::Distribute::BEGIN@22 |
23 | |||||
24 | #################################################################################################### | ||||
25 | |||||
26 | # distribute all sprites to areas | ||||
27 | # according to their configurations | ||||
28 | sub distribute | ||||
29 | # spent 30.4s (1.47+28.9) within OCBNET::Spritesets::Canvas::Distribute::distribute which was called 12 times, avg 2.53s/call:
# 12 times (1.47s+28.9s) by OCBNET::Spritesets::CSS::Parser::distribute at line 329 of webmerge/scripts/modules/OCBNET/Spritesets/CSS/Parser.pm, avg 2.53s/call | ||||
30 | |||||
31 | # get our object | ||||
32 | 12 | 52µs | my ($self) = @_; | ||
33 | |||||
34 | # a sprite that is enclosed can always be fitted. It's not | ||||
35 | # unnormal to have some offset for the image, but mostly the | ||||
36 | # container is nearly of the same size as the sprite. In some | ||||
37 | # cases the dev meant to use it left aligned in a big container. | ||||
38 | # then we should handle it as a left aligned image and put it | ||||
39 | # on the edge. This threshold determines when to fit and when | ||||
40 | # to put the sprite on the edge/stack area. Both padding will | ||||
41 | # be counted (outerWidth - width > threshold). | ||||
42 | 12 | 22µs | my $threshold = 40; | ||
43 | |||||
44 | ########################################################## | ||||
45 | |||||
46 | # reset area childrens (just in case) | ||||
47 | 12 | 150µs | foreach my $area (@{$self->{'areas'}}) | ||
48 | { $self->{$area}->{'children'} = []; } | ||||
49 | |||||
50 | ########################################################## | ||||
51 | |||||
52 | # reset distributed flag on all sprites | ||||
53 | 12 | 107µs | foreach my $sprite (@{$self->{'sprites'}}) | ||
54 | 4928 | 12.8ms | { $sprite->{'distributed'} = 0; } | ||
55 | |||||
56 | ########################################################## | ||||
57 | # DISTRIBUTERS | ||||
58 | ########################################################## | ||||
59 | |||||
60 | 12 | 888µs | my @distributers = ( | ||
61 | |||||
62 | # distribute one sprite into right top corner | ||||
63 | # optimum for height enclosed sprite left/bottom aligned | ||||
64 | # can remove height paddings and offset from top | ||||
65 | [ $self->{'corner-rt'}, 'isRepeating||alignRight||alignTop||isFixedX', 1 ], | ||||
66 | |||||
67 | # distribute one sprite into left bottom corner | ||||
68 | # optimum for width enclosed sprite right/top aligned | ||||
69 | # can remove width paddings and offset from left | ||||
70 | [ $self->{'corner-lb'}, 'isRepeating||alignLeft||alignBottom||isFixedY', 1 ], | ||||
71 | |||||
72 | # distribute one sprite into right bottom corners | ||||
73 | # optimum for non enclosed sprite left/top aligned | ||||
74 | # can remove all paddings and offset from left/top | ||||
75 | [ $self->{'corner-rb'}, 'isRepeating||alignRight||alignBottom||isFixedX||isFixedY', 1 ], | ||||
76 | |||||
77 | # distribute one sprite into left top corner | ||||
78 | # optimum for enclosed sprite right/bottom aligned | ||||
79 | # can remove paddings and offset from left/top | ||||
80 | [ $self->{'corner-lt'}, 'isRepeating||alignLeft||alignTop||isFlexibleY||isFlexibleX', 1 ], | ||||
81 | |||||
82 | # distribute the smaller items to the packed area to save precious space on the edges | ||||
83 | [ $self->{'middle'}, 'isFlexibleY||isFlexibleX||outerWidth-width>$threshold||outerHeight-height>$threshold' ], | ||||
84 | |||||
85 | # distribute sprites into edges/stacks | ||||
86 | [ $self->{'stack-l'}, 'isRepeating||alignLeft||isFlexibleY||isFlexibleX' ], | ||||
87 | [ $self->{'stack-t'}, 'isRepeating||alignTop||isFlexibleY||isFlexibleX' ], | ||||
88 | [ $self->{'stack-b'}, 'isRepeating||alignBottom||isFlexibleX' ], | ||||
89 | [ $self->{'stack-r'}, 'isRepeating||alignRight||isFlexibleY' ], | ||||
90 | |||||
91 | # distribute sprites into the packed center | ||||
92 | [ $self->{'middle'}, 'isFlexibleY||isFlexibleX' ], | ||||
93 | |||||
94 | # distribute sprites into edges | ||||
95 | [ $self->{'edge-t'}, 'alignBottom||isFlexibleX||isRepeatingBoth' ], | ||||
96 | [ $self->{'edge-l'}, 'alignRight||isFlexibleY||isRepeatingBoth' ], | ||||
97 | [ $self->{'edge-r'}, 'alignLeft||isFlexibleY||isRepeatingBoth' ], | ||||
98 | [ $self->{'edge-b'}, 'alignTop||isFlexibleX||isRepeatingBoth' ], | ||||
99 | |||||
100 | ); | ||||
101 | |||||
102 | ########################################################## | ||||
103 | |||||
104 | # process all distributers for all areas | ||||
105 | 12 | 64µs | foreach my $distributer (@distributers) | ||
106 | { | ||||
107 | |||||
108 | # get the options for this area distributer | ||||
109 | 168 | 1.26ms | my ($area, $excludes, $max) = @{$distributer}; | ||
110 | |||||
111 | # replace certain keywords to be an actual object call | ||||
112 | 168 | 11.7ms | 168 | 8.21ms | $excludes =~ s/\b(?=is|not|align|width|height|outer|padding)/\$_[0]->/g; # spent 8.21ms making 168 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:subst, avg 49µs/call |
113 | |||||
114 | # eval the condition into a pre-compiled subroutine to call | ||||
115 | 168 | 65.9ms | $excludes = eval sprintf 'sub { return (%s); };', $excludes; # spent 526ms executing statements in 12 string evals (merged) # includes 654ms spent executing 4896 calls to 1 sub defined therein. # spent 329ms executing statements in 12 string evals (merged) # includes 262ms spent executing 4168 calls to 1 sub defined therein. # spent 278ms executing statements in 12 string evals (merged) # includes 427ms spent executing 4184 calls to 1 sub defined therein. # spent 205ms executing statements in 12 string evals (merged) # includes 212ms spent executing 4088 calls to 1 sub defined therein. # spent 198ms executing statements in 12 string evals (merged) # includes 190ms spent executing 4056 calls to 1 sub defined therein. # spent 54.9ms executing statements in 12 string evals (merged) # includes 26.3ms spent executing 736 calls to 1 sub defined therein. # spent 39.5ms executing statements in 12 string evals (merged) # includes 27.0ms spent executing 764 calls to 1 sub defined therein. # spent 29.9ms executing statements in 12 string evals (merged) # includes 14.8ms spent executing 376 calls to 1 sub defined therein. # spent 19.4ms executing statements in 12 string evals (merged) # includes 23.2ms spent executing 720 calls to 1 sub defined therein. # spent 18.8ms executing statements in 12 string evals (merged) # includes 21.4ms spent executing 648 calls to 1 sub defined therein. # spent 17.6ms executing statements in 12 string evals (merged) # includes 72.1ms spent executing 672 calls to 1 sub defined therein. # spent 15.5ms executing statements in 12 string evals (merged) # includes 17.8ms spent executing 504 calls to 1 sub defined therein. # spent 13.5ms executing statements in 12 string evals (merged) # includes 34.0ms spent executing 440 calls to 1 sub defined therein. # spent 9.73ms executing statements in 12 string evals (merged) # includes 11.8ms spent executing 280 calls to 1 sub defined therein. | ||
116 | |||||
117 | # propagate any eval errors | ||||
118 | # not needed but just in case | ||||
119 | 168 | 151µs | die $@ if $@; | ||
120 | |||||
121 | # process each sprite to see if it should be | ||||
122 | # distributed into the currently checked area | ||||
123 | 168 | 81.6ms | foreach my $sprite (@{$self->{'sprites'}}) | ||
124 | { | ||||
125 | |||||
126 | # skip already distributed sprites | ||||
127 | 65792 | 119ms | next if $sprite->{'distributed'}; | ||
128 | |||||
129 | # check for failed excludes | ||||
130 | 26532 | 329ms | 26532 | 4.70s | next if $excludes->($sprite); # spent 2.10s making 4896 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 111)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 428µs/call
# spent 766ms making 4184 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 109)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 183µs/call
# spent 607ms making 4168 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 107)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 146µs/call
# spent 391ms making 4088 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 108)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 96µs/call
# spent 371ms making 4056 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 110)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 91µs/call
# spent 84.9ms making 672 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 101)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 126µs/call
# spent 84.8ms making 440 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 104)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 193µs/call
# spent 53.0ms making 648 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 102)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 82µs/call
# spent 48.1ms making 764 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 112)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 63µs/call
# spent 45.3ms making 736 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 113)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 62µs/call
# spent 42.4ms making 280 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 106)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 152µs/call
# spent 40.7ms making 504 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 103)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 81µs/call
# spent 39.3ms making 720 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 100)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 55µs/call
# spent 34.4ms making 376 calls to OCBNET::Spritesets::Canvas::Distribute::__ANON__[(eval 105)[webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Distribute.pm:115]:1], avg 92µs/call |
131 | |||||
132 | # add sprite to area | ||||
133 | 4744 | 52.1ms | 4744 | 95.7ms | $area->add($sprite); # spent 95.7ms making 4744 calls to OCBNET::Spritesets::Container::add, avg 20µs/call |
134 | |||||
135 | # set the distributed flag | ||||
136 | 4744 | 12.6ms | $sprite->{'distributed'} = 1; | ||
137 | |||||
138 | # check if we have distributed enough sprites | ||||
139 | 4744 | 18.7ms | last if $max && scalar(@{$area->{'children'}}) >= $max; | ||
140 | |||||
141 | } | ||||
142 | # EO each sprite | ||||
143 | |||||
144 | } | ||||
145 | # EO each distributer | ||||
146 | |||||
147 | ########################################################## | ||||
148 | |||||
149 | # optimize space between repeaters | ||||
150 | 96 | 3.38ms | 320 | 3.21ms | @{$self->{'edge-l'}->{'children'}} = # spent 1.97ms making 192 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call
# spent 1.24ms making 128 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 10µs/call |
151 | sort { $a->isRepeatX - $b->isRepeatX || $a->isFixedX - $b->isFixedX } | ||||
152 | 12 | 404µs | 12 | 8.18ms | @{$self->{'edge-l'}->{'children'}}; # spent 8.18ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 682µs/call |
153 | |||||
154 | # optimize space between repeaters | ||||
155 | 192 | 6.36ms | 640 | 6.27ms | @{$self->{'edge-r'}->{'children'}} = # spent 3.80ms making 384 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call
# spent 2.47ms making 256 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 10µs/call |
156 | sort { $b->isRepeatX - $a->isRepeatX || $a->isFixedX - $b->isFixedX } | ||||
157 | 12 | 225µs | 12 | 15.9ms | @{$self->{'edge-r'}->{'children'}}; # spent 15.9ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 1.32ms/call |
158 | |||||
159 | # optimize space between repeaters | ||||
160 | 96 | 3.22ms | 320 | 3.20ms | @{$self->{'edge-t'}->{'children'}} = # spent 1.92ms making 192 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
# spent 1.28ms making 128 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 10µs/call |
161 | sort { $a->isRepeatY - $b->isRepeatY || $a->isFixedY - $b->isFixedY } | ||||
162 | 12 | 198µs | 12 | 8.05ms | @{$self->{'edge-t'}->{'children'}}; # spent 8.05ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 671µs/call |
163 | |||||
164 | # optimize space between repeaters | ||||
165 | 224 | 7.44ms | 768 | 7.50ms | @{$self->{'edge-b'}->{'children'}} = # spent 4.43ms making 448 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
# spent 3.06ms making 320 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 10µs/call |
166 | sort { $b->isRepeatY - $a->isRepeatY || $a->isFixedY - $b->isFixedY } | ||||
167 | 12 | 179µs | 12 | 38.3ms | @{$self->{'edge-b'}->{'children'}}; # spent 38.3ms making 12 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sort, avg 3.19ms/call |
168 | |||||
169 | ########################################################## | ||||
170 | |||||
171 | # unsupported sprites | ||||
172 | 12 | 26µs | my $unsupported = 0; | ||
173 | |||||
174 | # check for sprite that have not been distributed | ||||
175 | # there are quite a few configurations that cannot | ||||
176 | # be handled - inform the user about these problems | ||||
177 | 12 | 3.58ms | foreach my $sprite (@{$self->{'sprites'}}) | ||
178 | { | ||||
179 | # distributed are the ones we like | ||||
180 | 4928 | 6.73ms | next if $sprite->{'distributed'}; | ||
181 | # only print header warning once | ||||
182 | 184 | 140µs | unless ($unsupported) | ||
183 | { | ||||
184 | 8 | 744µs | warn "\nWARNING: Some sprites are configured to be included within\n" . | ||
185 | "a spriteset, but are not possible to distribute to any area, due\n" . | ||||
186 | "to invalid styles (like repeating or beeing flexible in both axes)!\n\n"; | ||||
187 | } | ||||
188 | # print each unsupported sprite to the console | ||||
189 | 184 | 21.6ms | 1104 | 11.8ms | warn sprintf " url(%s) enc(%s/%s), rep(%s/%s), pos(%s/%s)\n", # spent 2.24ms making 184 calls to OCBNET::Spritesets::Sprite::isFixedX, avg 12µs/call
# spent 2.00ms making 184 calls to OCBNET::Spritesets::Sprite::isFixedY, avg 11µs/call
# spent 1.94ms making 184 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 11µs/call
# spent 1.90ms making 184 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
# spent 1.90ms making 184 calls to OCBNET::Spritesets::Sprite::positionX, avg 10µs/call
# spent 1.86ms making 184 calls to OCBNET::Spritesets::Sprite::positionY, avg 10µs/call |
190 | substr($sprite->{'filename'}, - 25), | ||||
191 | $sprite->isFixedX, $sprite->isFixedY, | ||||
192 | $sprite->isRepeatX, $sprite->isRepeatY, | ||||
193 | $sprite->positionX, $sprite->positionY; | ||||
194 | # increase counter | ||||
195 | 184 | 883µs | $unsupported ++; | ||
196 | } | ||||
197 | |||||
198 | # wait a second make user more | ||||
199 | # aware that some problem exists | ||||
200 | 12 | 24.0s | 8 | 24.0s | sleep 3 if $unsupported; # spent 24.0s making 8 calls to OCBNET::Spritesets::Canvas::Distribute::CORE:sleep, avg 3.00s/call |
201 | |||||
202 | } | ||||
203 | # EO sub distribute | ||||
204 | |||||
205 | #################################################################################################### | ||||
206 | #################################################################################################### | ||||
207 | 1 | 12µs | 1; | ||
# spent 24.0s within OCBNET::Spritesets::Canvas::Distribute::CORE:sleep which was called 8 times, avg 3.00s/call:
# 8 times (24.0s+0s) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 200, avg 3.00s/call | |||||
# spent 70.3ms (50.2+20.2) within OCBNET::Spritesets::Canvas::Distribute::CORE:sort which was called 48 times, avg 1.47ms/call:
# 12 times (30.8ms+7.50ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 167, avg 3.19ms/call
# 12 times (9.58ms+6.27ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 157, avg 1.32ms/call
# 12 times (4.97ms+3.21ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 152, avg 682µs/call
# 12 times (4.85ms+3.20ms) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 162, avg 671µs/call | |||||
# spent 8.21ms within OCBNET::Spritesets::Canvas::Distribute::CORE:subst which was called 168 times, avg 49µs/call:
# 168 times (8.21ms+0s) by OCBNET::Spritesets::Canvas::Distribute::distribute at line 112, avg 49µs/call |