← Index
NYTProf Performance Profile   « line view »
For webmerge/scripts/webmerge.pl
  Run on Mon Oct 7 02:42:42 2013
Reported on Mon Oct 7 03:03:18 2013

Filename/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Layout.pm
StatementsExecuted 47239 statements in 445ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1211408ms92.7sOCBNET::Spritesets::Canvas::Layout::::layoutOCBNET::Spritesets::Canvas::Layout::layout
9568142108ms108msOCBNET::Spritesets::Canvas::Layout::::snapOCBNET::Spritesets::Canvas::Layout::snap
5843122.9ms25.4msOCBNET::Spritesets::Canvas::Layout::::factorsOCBNET::Spritesets::Canvas::Layout::factors
14412111.9ms29.2msOCBNET::Spritesets::Canvas::Layout::::lcmOCBNET::Spritesets::Canvas::Layout::lcm
1112.81ms30.4msOCBNET::Spritesets::Canvas::Layout::::BEGIN@31OCBNET::Spritesets::Canvas::Layout::BEGIN@31
584112.51ms2.51msOCBNET::Spritesets::Canvas::Layout::::CORE:sortOCBNET::Spritesets::Canvas::Layout::CORE:sort (opcode)
1111.36ms16.6msOCBNET::Spritesets::Canvas::Layout::::BEGIN@231OCBNET::Spritesets::Canvas::Layout::BEGIN@231
111104µs203µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@10OCBNET::Spritesets::Canvas::Layout::BEGIN@10
11156µs87µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@11OCBNET::Spritesets::Canvas::Layout::BEGIN@11
11155µs55µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@19.1OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1
11126µs26µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@22OCBNET::Spritesets::Canvas::Layout::BEGIN@22
11126µs26µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@25OCBNET::Spritesets::Canvas::Layout::BEGIN@25
11124µs24µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@19OCBNET::Spritesets::Canvas::Layout::BEGIN@19
11121µs21µsOCBNET::Spritesets::Canvas::Layout::::BEGIN@16OCBNET::Spritesets::Canvas::Layout::BEGIN@16
Call graph for these subroutines as a Graphviz dot language file.
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####################################################################################################
7package OCBNET::Spritesets::Canvas::Layout;
8####################################################################################################
9
102172µs2302µs
# spent 203µs (104+99) within OCBNET::Spritesets::Canvas::Layout::BEGIN@10 which was called: # once (104µs+99µs) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 10
use strict;
# spent 203µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@10 # spent 99µs making 1 call to strict::import
112192µs2118µs
# spent 87µs (56+31) within OCBNET::Spritesets::Canvas::Layout::BEGIN@11 which was called: # once (56µs+31µs) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 11
use warnings;
# spent 87µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@11 # spent 31µs making 1 call to warnings::import
12
13###################################################################################################
14
15# define our version string
161157µs121µs
# spent 21µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@16 which was called: # once (21µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 16
BEGIN { $OCBNET::Spritesets::Canvas::Layout = "0.70"; }
# spent 21µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@16
17
18# load exporter and inherit from it
193374µs279µs
# spent 24µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@19 which was called: # once (24µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 19 # spent 55µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1 which was called: # once (55µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 19
BEGIN { use Exporter qw(); our @ISA = qw(Exporter); }
# spent 55µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1 # spent 24µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@19
20
21# define our functions to be exported
221175µs126µs
# spent 26µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@22 which was called: # once (26µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 22
BEGIN { our @EXPORT = qw(layout snap); }
# spent 26µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@22
23
24# define our functions to be exported
251170µs126µs
# spent 26µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@25 which was called: # once (26µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 25
BEGIN { our @EXPORT_OK = qw(factors lcm); }
# spent 26µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@25
26
27####################################################################################################
28
29# load function from core module
30# ******************************************************************************
3124.35ms231.1ms
# spent 30.4ms (2.81+27.6) within OCBNET::Spritesets::Canvas::Layout::BEGIN@31 which was called: # once (2.81ms+27.6ms) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 31
use List::MoreUtils qw(uniq);
# spent 30.4ms making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@31 # spent 700µs making 1 call to Exporter::import
32
33
34# private helper function
35# returns all prime factors
36# ******************************************************************************
37sub factors
38
# spent 25.4ms (22.9+2.51) within OCBNET::Spritesets::Canvas::Layout::factors which was called 584 times, avg 44µs/call: # 456 times (14.5ms+1.48ms) by OCBNET::Spritesets::Canvas::Layout::lcm at line 73, avg 35µs/call # 64 times (4.38ms+557µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 145, avg 77µs/call # 64 times (4.08ms+470µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 131, avg 71µs/call
{
39
40 # hold all factors
41584454µs my @primes;
42
43 # get number to factorize
445841.45ms my ($number) = @_;
45
46 # loop from 2 up to number
475843.50ms for ( my $y = 2; $y <= $number; $y ++ )
48 {
49 # skip if not a factor
5015122.55ms next if $number % $y;
51 # divide by factor found
52504721µs $number /= $y;
53 # store found factor
545041.08ms push(@primes, $y);
55 # restart from 2
56504616µs redo;
57 }
58
59 # sort the prime factors
6058417.4ms5842.51ms return sort @primes;
# spent 2.51ms making 584 calls to OCBNET::Spritesets::Canvas::Layout::CORE:sort, avg 4µs/call
61
62};
63# EO sub factors
64
65####################################################################################################
66
67# private helper function
68# least common multiplier
69# ******************************************************************************
70sub lcm
71
# spent 29.2ms (11.9+17.3) within OCBNET::Spritesets::Canvas::Layout::lcm which was called 144 times, avg 203µs/call: # 12 times (1.52ms+2.80ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 209, avg 360µs/call # 12 times (1.47ms+2.66ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 218, avg 344µs/call # 12 times (1.31ms+1.89ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 166, avg 267µs/call # 12 times (1.18ms+1.80ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 172, avg 248µs/call # 12 times (1.13ms+1.77ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 195, avg 241µs/call # 12 times (1.11ms+1.72ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 202, avg 235µs/call # 12 times (928µs+1.40ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 184, avg 194µs/call # 12 times (926µs+1.32ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 179, avg 187µs/call # 12 times (580µs+497µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 190, avg 90µs/call # 12 times (574µs+499µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 192, avg 89µs/call # 12 times (573µs+499µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 193, avg 89µs/call # 12 times (566µs+494µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 191, avg 88µs/call
{
72144217µs my $product = 1; $product *= $_
736009.99ms60017.3ms foreach uniq grep { $_ != 0 }
# spent 15.9ms making 456 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 35µs/call # spent 1.40ms making 144 calls to List::MoreUtils::uniq, avg 10µs/call
74 map { factors($_) } @_;
751442.24ms return $product;
76}
77# EO sub lcm
78
79####################################################################################################
80
81# snap value to given multiplier
82# ******************************************************************************
83sub snap
84
# spent 108ms within OCBNET::Spritesets::Canvas::Layout::snap which was called 9568 times, avg 11µs/call: # 4712 times (54.0ms+0s) by OCBNET::Spritesets::Container::layout at line 159 of webmerge/scripts/modules/OCBNET/Spritesets/Container.pm, avg 11µs/call # 4712 times (52.2ms+0s) by OCBNET::Spritesets::Container::layout at line 160 of webmerge/scripts/modules/OCBNET/Spritesets/Container.pm, avg 11µs/call # 12 times (166µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 247, avg 14µs/call # 12 times (133µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 300, avg 11µs/call # 12 times (124µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 355, avg 10µs/call # 12 times (122µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 261, avg 10µs/call # 12 times (122µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 269, avg 10µs/call # 12 times (120µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 301, avg 10µs/call # 12 times (115µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 270, avg 10µs/call # 12 times (115µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 248, avg 10µs/call # 12 times (114µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 356, avg 10µs/call # 12 times (113µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 262, avg 9µs/call # 12 times (111µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 271, avg 9µs/call # 12 times (110µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 272, avg 9µs/call
{
85 # get rest by modulo divide
86956832.1ms my $rest = $_[0] % $_[1];
87 # add rest to fill up to multipler
889568170ms $_[0] += $rest ? $_[1] - $rest : 0;
89}
90# EO sub snap
91
92####################################################################################################
93
94# layout all child nodes
95# updates dimensions and positions
96# ******************************************************************************
97sub layout
98
# spent 92.7s (408ms+92.3) within OCBNET::Spritesets::Canvas::Layout::layout which was called 12 times, avg 7.73s/call: # 12 times (408ms+92.3s) by OCBNET::Spritesets::CSS::Parser::write at line 410 of webmerge/scripts/modules/OCBNET/Spritesets/CSS/Parser.pm, avg 7.73s/call
{
99
100 # get our object
1011245µs my ($self) = shift;
102
103 ##########################################################
104 # CALL LAYOUT ON EACH AREA
105 ##########################################################
106
107 # call layout method on all areas
108122.61ms16892.0s $_->layout(@_) foreach ($self->areas);
# spent 91.2s making 12 calls to OCBNET::Spritesets::Fit::layout, avg 7.60s/call # spent 534ms making 48 calls to OCBNET::Spritesets::Edge::layout, avg 11.1ms/call # spent 192ms making 48 calls to OCBNET::Spritesets::Stack::layout, avg 4.01ms/call # spent 60.7ms making 48 calls to OCBNET::Spritesets::Corner::layout, avg 1.26ms/call # spent 663µs making 12 calls to OCBNET::Spritesets::Canvas::areas, avg 55µs/call
109
110 ##########################################################
111 # GET MULTIPLIERS FOR DIMENSIONS AND REPEATING
112 ##########################################################
113
114 # declare repating arrays
1151243µs my (%repeat_x, %repeat_y);
116
117 # process all sprites in canvas
118121.64ms122.67ms foreach my $sprite ($self->sprites)
# spent 2.67ms making 12 calls to OCBNET::Spritesets::Canvas::sprites, avg 222µs/call
119 {
120
121 # skip not distributed sprites
12249289.92ms next unless $sprite->{'distributed'};
123
124 # assertion for not repeating in both directions
125474443.5ms497649.7ms if ($sprite->isRepeatX && $sprite->isRepeatY)
# spent 47.3ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call # spent 2.40ms making 232 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
126 { die "fatal: cannot repeat in both directions"; }
127
128 # make sure we can repeat this sprite perfectly
129474444.9ms497652.8ms if ($sprite->isRepeatX && $sprite->isFlexibleX)
# spent 45.1ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call # spent 7.75ms making 232 calls to OCBNET::Spritesets::Sprite::isFlexibleX, avg 33µs/call
130 {
131641.45ms1285.23ms my @factors = factors($sprite->width);
# spent 4.55ms making 64 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 71µs/call # spent 679µs making 64 calls to OCBNET::Spritesets::Block::width, avg 11µs/call
132128969µs my %factors; ++ $factors{$_} foreach @factors;
13364724µs foreach (keys %factors)
134 {
135128180µs $repeat_x{$_} = 0 unless exists $repeat_x{$_};
136128184µs next if $repeat_x{$_} > $factors{$_};
137128418µs $repeat_x{$_} = $factors{$_};
138 }
139 }
140
141 # make sure we can repeat this sprite perfectly
142474454.9ms497654.0ms if ($sprite->isRepeatY && $sprite->isFlexibleY)
# spent 46.4ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call # spent 7.62ms making 232 calls to OCBNET::Spritesets::Sprite::isFlexibleY, avg 33µs/call
143 {
144
145641.47ms1285.62ms my @factors = factors($sprite->height);
# spent 4.94ms making 64 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 77µs/call # spent 676µs making 64 calls to OCBNET::Spritesets::Block::height, avg 11µs/call
1461281.00ms my %factors; ++ $factors{$_} foreach @factors;
14764799µs foreach (keys %factors)
148 {
149128195µs $repeat_y{$_} = 0 unless exists $repeat_y{$_};
150128186µs next if $repeat_y{$_} > $factors{$_};
151128433µs $repeat_y{$_} = $factors{$_};
152 }
153 }
154
155 }
156 # EO each sprite
157
158 # calculate the lowest denominator for repeating snaping values
15924343µs my $repeat_x = 1; $repeat_x *= $_ ** $repeat_x{$_} foreach keys %repeat_x;
16024215µs my $repeat_y = 1; $repeat_y *= $_ ** $repeat_y{$_} foreach keys %repeat_y;
161
162 ##########################################################
163 # GET LIMITS FROM SNAPPED ELEMENTS
164 ##########################################################
165
16612863µs609.29ms my $col1_snap_w = lcm(
# spent 6.09ms making 48 calls to OCBNET::Spritesets::Container::scaleX, avg 127µs/call # spent 3.20ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 267µs/call
167 $self->{'edge-l'}->scaleX,
168 $self->{'stack-l'}->scaleX,
169 $self->{'corner-lb'}->scaleX,
170 $self->{'corner-lt'}->scaleX
171 );
17212789µs608.24ms my $row1_snap_h = lcm(
# spent 5.27ms making 48 calls to OCBNET::Spritesets::Container::scaleY, avg 110µs/call # spent 2.98ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 248µs/call
173 $self->{'edge-t'}->scaleY,
174 $self->{'stack-t'}->scaleY,
175 $self->{'corner-rt'}->scaleY,
176 $self->{'corner-lt'}->scaleY
177 );
178
17912569µs483.68ms my $col2_snap_w = lcm(
# spent 2.25ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 187µs/call # spent 1.44ms making 36 calls to OCBNET::Spritesets::Container::scaleX, avg 40µs/call
180 $self->{'stack-t'}->scaleX,
181 $self->{'middle'}->scaleX,
182 $self->{'stack-b'}->scaleX
183 );
18412534µs483.66ms my $row2_snap_h = lcm(
# spent 2.32ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 194µs/call # spent 1.34ms making 36 calls to OCBNET::Spritesets::Container::scaleY, avg 37µs/call
185 $self->{'stack-l'}->scaleY,
186 $self->{'middle'}->scaleY,
187 $self->{'stack-r'}->scaleY
188 );
189
19012277µs241.67ms my $col3_snap_w = lcm($self->{'edge-t'}->scaleX);
# spent 1.08ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 90µs/call # spent 593µs making 12 calls to OCBNET::Spritesets::Container::scaleX, avg 49µs/call
19112255µs241.62ms my $row3_snap_h = lcm($self->{'edge-l'}->scaleY);
# spent 1.06ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 88µs/call # spent 560µs making 12 calls to OCBNET::Spritesets::Container::scaleY, avg 47µs/call
19212259µs241.65ms my $col4_snap_w = lcm($self->{'edge-b'}->scaleX);
# spent 1.07ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 89µs/call # spent 581µs making 12 calls to OCBNET::Spritesets::Container::scaleX, avg 48µs/call
19312244µs241.63ms my $row4_snap_h = lcm($self->{'edge-r'}->scaleY);
# spent 1.07ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 89µs/call # spent 558µs making 12 calls to OCBNET::Spritesets::Container::scaleY, avg 47µs/call
194
19512681µs608.35ms my $col_snap_last_w = lcm(
# spent 5.45ms making 48 calls to OCBNET::Spritesets::Container::scaleX, avg 113µs/call # spent 2.90ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 241µs/call
196 $self->{'edge-r'}->scaleX,
197 $self->{'stack-r'}->scaleX,
198 $self->{'corner-rb'}->scaleX,
199 $self->{'corner-rt'}->scaleX
200 );
201
20212692µs607.91ms my $row_snap_last_h = lcm(
# spent 5.09ms making 48 calls to OCBNET::Spritesets::Container::scaleY, avg 106µs/call # spent 2.82ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 235µs/call
203 $self->{'edge-b'}->scaleY,
204 $self->{'stack-b'}->scaleY,
205 $self->{'corner-lb'}->scaleY,
206 $self->{'corner-rb'}->scaleY
207 );
208
20912140µs124.32ms my $col_snap_w = lcm(
# spent 4.32ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 360µs/call
210 $repeat_x,
211 $col1_snap_w,
212 $col2_snap_w,
213 $col3_snap_w,
214 $col4_snap_w,
215 $col_snap_last_w
216 );
217
21812124µs124.12ms my $row_snap_h = lcm(
# spent 4.12ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 344µs/call
219 $repeat_y,
220 $row1_snap_h,
221 $row2_snap_h,
222 $row3_snap_h,
223 $row4_snap_h,
224 $row_snap_last_h
225 );
226
227 ##########################################################
228 # GET LIMITS FROM SNAPPED ELEMENTS
229 ##########################################################
230
23125.61ms217.0ms
# spent 16.6ms (1.36+15.3) within OCBNET::Spritesets::Canvas::Layout::BEGIN@231 which was called: # once (1.36ms+15.3ms) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 231
use List::Util qw[min max];
# spent 16.6ms making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@231 # spent 410µs making 1 call to Exporter::import
232
233121.00ms604.35ms my $col1_w = max(
# spent 4.23ms making 48 calls to OCBNET::Spritesets::Block::outerWidth, avg 88µs/call # spent 114µs making 12 calls to List::Util::max, avg 10µs/call
234 $self->{'edge-l'}->outerWidth,
235 $self->{'stack-l'}->outerWidth,
236 $self->{'corner-lb'}->outerWidth,
237 $self->{'corner-lt'}->outerWidth
238 );
239
24012857µs604.14ms my $row1_h = max(
# spent 4.07ms making 48 calls to OCBNET::Spritesets::Block::outerHeight, avg 85µs/call # spent 71µs making 12 calls to List::Util::max, avg 6µs/call
241 $self->{'edge-t'}->outerHeight,
242 $self->{'stack-t'}->outerHeight,
243 $self->{'corner-rt'}->outerHeight,
244 $self->{'corner-lt'}->outerHeight
245 );
246
24712113µs12166µs snap ($col1_w, $col1_snap_w);
# spent 166µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 14µs/call
2481289µs12115µs snap ($row1_h, $row1_snap_h);
# spent 115µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
249
25012678µs482.97ms my $col2_w = max(
# spent 2.90ms making 36 calls to OCBNET::Spritesets::Block::outerWidth, avg 81µs/call # spent 72µs making 12 calls to List::Util::max, avg 6µs/call
251 $self->{'stack-t'}->outerWidth,
252 $self->{'middle'}->outerWidth,
253 $self->{'stack-b'}->outerWidth
254 );
25512650µs482.98ms my $row2_h = max(
# spent 2.91ms making 36 calls to OCBNET::Spritesets::Block::outerHeight, avg 81µs/call # spent 73µs making 12 calls to List::Util::max, avg 6µs/call
256 $self->{'stack-l'}->outerHeight,
257 $self->{'middle'}->outerHeight,
258 $self->{'stack-r'}->outerHeight
259 );
260
2611292µs12122µs snap ($col2_w, $col2_snap_w);
# spent 122µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
2621292µs12113µs snap ($row2_h, $row2_snap_h);
# spent 113µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call
263
26412151µs12952µs my $col3_w = $self->{'edge-t'}->outerWidth;
# spent 952µs making 12 calls to OCBNET::Spritesets::Block::outerWidth, avg 79µs/call
26512149µs12984µs my $row3_h = $self->{'edge-l'}->outerHeight;
# spent 984µs making 12 calls to OCBNET::Spritesets::Block::outerHeight, avg 82µs/call
26612142µs12946µs my $col4_w = $self->{'edge-b'}->outerWidth;
# spent 946µs making 12 calls to OCBNET::Spritesets::Block::outerWidth, avg 79µs/call
26712154µs121.01ms my $row4_h = $self->{'edge-r'}->outerHeight;
# spent 1.01ms making 12 calls to OCBNET::Spritesets::Block::outerHeight, avg 85µs/call
268
2691297µs12122µs snap ($col3_w, $col3_snap_w);
# spent 122µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
2701288µs12115µs snap ($row3_h, $row3_snap_h);
# spent 115µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
2711287µs12111µs snap ($col4_w, $col4_snap_w);
# spent 111µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call
2721290µs12110µs snap ($row4_h, $row4_snap_h);
# spent 110µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call
273
27412752µs603.82ms my $col_last_w = max(
# spent 3.75ms making 48 calls to OCBNET::Spritesets::Block::outerWidth, avg 78µs/call # spent 76µs making 12 calls to List::Util::max, avg 6µs/call
275 $self->{'edge-r'}->outerWidth,
276 $self->{'stack-r'}->outerWidth,
277 $self->{'corner-rb'}->outerWidth,
278 $self->{'corner-rt'}->outerWidth
279 );
280
28112740µs603.85ms my $row_last_h = max(
# spent 3.78ms making 48 calls to OCBNET::Spritesets::Block::outerHeight, avg 79µs/call # spent 70µs making 12 calls to List::Util::max, avg 6µs/call
282 $self->{'edge-b'}->outerHeight,
283 $self->{'stack-b'}->outerHeight,
284 $self->{'corner-lb'}->outerHeight,
285 $self->{'corner-rb'}->outerHeight
286 );
287
2881213µs my $col1_x = $col1_w;
2891212µs my $row1_y = $row1_h;
290
2911232µs my $col2_x = $col1_x + $col2_w;
2921214µs my $row2_y = $row1_y + $row2_h;
293
294 # make sure both sides will fit our repeating pattern
295 # this can blow up the sprite by quite some factor if your image
296 # dimensions have lots of different factors in it, if they are all
297 # about the same size and not too big, this should work quite well
2981218µs my $snap_w = $col2_x + $col3_w + $col4_w + $col_last_w;
2991232µs my $snap_h = $row2_y + $row3_h + $row4_h + $row_last_h;
30012109µs12133µs snap(my $snapped_w = $snap_w, $repeat_x);
# spent 133µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 11µs/call
3011297µs12120µs snap(my $snapped_h = $snap_h, $repeat_y);
# spent 120µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
3021230µs $col2_x += $snapped_w - $snap_w;
3031217µs $row2_y += $snapped_h - $snap_h;
304
3051216µs my $col3_x = $col2_x + $col3_w;
3061213µs my $col4_x = $col3_x + $col4_w;
307
3081213µs my $row3_y = $row2_y + $row3_h;
3091211µs my $row4_y = $row3_y + $row4_h;
310
311 ##########################################################
312 # CALCULATE LAYOUT
313 ##########################################################
314
315128µs my $width = 0;
316128µs my $height = 0;
317
318 ##########################################################
319 # we have 13 areas, so 26 positions to set
320 ##########################################################
321
322 # leave the first row in place (8)
32312190µs12142µs $self->{'corner-lt'}->top = 0;
# spent 142µs making 12 calls to OCBNET::Spritesets::Block::top, avg 12µs/call
32412168µs12137µs $self->{'corner-lt'}->left = 0;
# spent 137µs making 12 calls to OCBNET::Spritesets::Block::left, avg 11µs/call
32512151µs12115µs $self->{'stack-t'}->top = 0;
# spent 115µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
32612153µs12117µs $self->{'stack-l'}->left = 0;
# spent 117µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
32712160µs12117µs $self->{'edge-t'}->top = 0;
# spent 117µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
32812146µs12118µs $self->{'edge-l'}->left = 0;
# spent 118µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
32912132µs12114µs $self->{'corner-rt'}->top = 0;
# spent 114µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
33012134µs12112µs $self->{'corner-lb'}->left = 0;
# spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call
331
332 ##########################################################
333
334 # move the second row aways (6)
33512138µs12113µs $self->{'stack-l'}->top = $row1_y;
# spent 113µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call
33612155µs12114µs $self->{'middle'}->top = $row1_y;
# spent 114µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
33712133µs12111µs $self->{'stack-r'}->top = $row1_y;
# spent 111µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call
33812136µs12113µs $self->{'stack-t'}->left = $col1_x;
# spent 113µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call
33912149µs12115µs $self->{'middle'}->left = $col1_x;
# spent 115µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
34012137µs12112µs $self->{'stack-b'}->left = $col1_x;
# spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call
341
342 ##########################################################
343
344 # move the third row aways (4)
34512136µs12112µs $self->{'edge-l'}->top = $row2_y;
# spent 112µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call
34612132µs12110µs $self->{'edge-r'}->top = $row3_y;
# spent 110µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call
34712134µs12115µs $self->{'edge-t'}->left = $col2_x;
# spent 115µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
34812134µs12112µs $self->{'edge-b'}->left = $col3_x;
# spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call
349
350 ##########################################################
351
35212154µs12123µs my $w = $width = $self->width = $col4_x + $col_last_w;
# spent 123µs making 12 calls to OCBNET::Spritesets::Block::width, avg 10µs/call
35312143µs12116µs my $h = $height = $self->height = $row4_y + $row_last_h;
# spent 116µs making 12 calls to OCBNET::Spritesets::Block::height, avg 10µs/call
354
3551296µs12124µs snap ($w, $repeat_x);
# spent 124µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
3561287µs12114µs snap ($h, $repeat_y);
# spent 114µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call
357
3581223µs die "width invalid: $width $w" if $w != $width;
3591211µs die "height invalid: $height $h" if $h != $height;
360
361 ##########################################################
362
363 # move the fourth row aways (8)
364 # align them to the right / bottom
36512450µs3622.5ms $self->{'corner-rb'}->top = $self->outerHeight - $self->{'corner-rb'}->outerHeight;
# spent 22.4ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 934µs/call # spent 138µs making 12 calls to OCBNET::Spritesets::Block::top, avg 11µs/call
36612461µs362.11ms $self->{'corner-rb'}->left = $self->outerWidth - $self->{'corner-rb'}->outerWidth;
# spent 1.96ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 82µs/call # spent 152µs making 12 calls to OCBNET::Spritesets::Block::left, avg 13µs/call
36712380µs362.01ms $self->{'stack-b'}->top = $self->outerHeight - $self->{'stack-b'}->outerHeight;
# spent 1.90ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 79µs/call # spent 116µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
36812386µs362.05ms $self->{'stack-r'}->left = $self->outerWidth - $self->{'stack-r'}->outerWidth;
# spent 1.93ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call # spent 118µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
36912383µs362.03ms $self->{'edge-b'}->top = $self->outerHeight - $self->{'edge-b'}->outerHeight;
# spent 1.91ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 80µs/call # spent 118µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
37012387µs362.04ms $self->{'edge-r'}->left = $self->outerWidth - $self->{'edge-r'}->outerWidth;
# spent 1.92ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call # spent 119µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
37112385µs362.03ms $self->{'corner-lb'}->top = $self->outerHeight - $self->{'corner-lb'}->outerHeight;
# spent 1.92ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 80µs/call # spent 118µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
37212388µs362.05ms $self->{'corner-rt'}->left = $self->outerWidth - $self->{'corner-rt'}->outerWidth;
# spent 1.93ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call # spent 121µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
373
374 ##########################################################
375 # RE-ALIGN WIDGETS AFTER SNAPPING
376 ##########################################################
377
378 # layout all children
37912368µs12583µs foreach my $area ($self->areas)
# spent 583µs making 12 calls to OCBNET::Spritesets::Canvas::areas, avg 49µs/call
380 {
381
382 # ignore area if it's empty
3831561.65ms1562.02ms next if $area->empty;
# spent 2.02ms making 156 calls to OCBNET::Spritesets::Container::empty, avg 13µs/call
384
385 # adjust layout only for stacked (repeating) elements
3861082.68ms1081.10ms next unless $area->isa('OCBNET::Spritesets::Stack');
# spent 1.10ms making 108 calls to UNIVERSAL::isa, avg 10µs/call
387
388 # re-align the sub area
389641.51ms1441.46ms if ($area->alignOpp)
# spent 650µs making 64 calls to OCBNET::Spritesets::Stack::alignOpp, avg 10µs/call # spent 339µs making 32 calls to OCBNET::Spritesets::Stack::stackVert, avg 11µs/call # spent 313µs making 32 calls to OCBNET::Spritesets::Block::width, avg 10µs/call # spent 162µs making 16 calls to OCBNET::Spritesets::Block::left, avg 10µs/call
390 {
391 if ($area->stackVert)
392 { $area->left = $self->width - $area->width; }
39316470µs48463µs else { $area->top = $self->height - $area->height; }
# spent 309µs making 32 calls to OCBNET::Spritesets::Block::height, avg 10µs/call # spent 154µs making 16 calls to OCBNET::Spritesets::Block::top, avg 10µs/call
394 }
395
396 }
397 # EO each area
398
399 # return success
40012633µs return $self;
401
402}
403# EO sub layout
404
405####################################################################################################
406####################################################################################################
407113µs1;
 
# spent 2.51ms within OCBNET::Spritesets::Canvas::Layout::CORE:sort which was called 584 times, avg 4µs/call: # 584 times (2.51ms+0s) by OCBNET::Spritesets::Canvas::Layout::factors at line 60, avg 4µs/call
sub OCBNET::Spritesets::Canvas::Layout::CORE:sort; # opcode