Skip to content

Commit 2bbe157

Browse files
author
Ilya Melnitskiy
committed
Remove unnecessary x/y calculations for performance
1 parent 1111de2 commit 2bbe157

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

col.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -556,26 +556,7 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
556556
// width # Width of object frame.
557557
// height # Height of object frame.
558558
//
559-
// xAbs # Absolute distance to left side of object.
560-
// yAbs # Absolute distance to top side of object.
561-
//
562-
func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int, int, int) {
563-
xAbs := 0
564-
yAbs := 0
565-
566-
// Calculate the absolute x offset of the top-left vertex.
567-
for colID := 1; colID <= col; colID++ {
568-
xAbs += f.getColWidth(sheet, colID)
569-
}
570-
xAbs += x1
571-
572-
// Calculate the absolute y offset of the top-left vertex.
573-
// Store the column change to allow optimisations.
574-
for rowID := 1; rowID <= row; rowID++ {
575-
yAbs += f.getRowHeight(sheet, rowID)
576-
}
577-
yAbs += y1
578-
559+
func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) {
579560
// Adjust start column for offsets that are greater than the col width.
580561
for x1 >= f.getColWidth(sheet, col) {
581562
x1 -= f.getColWidth(sheet, col)
@@ -610,7 +591,7 @@ func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, heigh
610591
// The end vertices are whatever is left from the width and height.
611592
x2 := width
612593
y2 := height
613-
return col, row, xAbs, yAbs, colEnd, rowEnd, x2, y2
594+
return col, row, colEnd, rowEnd, x2, y2
614595
}
615596

616597
// getColWidth provides a function to get column width in pixels by given

drawing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rI
11801180

11811181
width = int(float64(width) * formatSet.XScale)
11821182
height = int(float64(height) * formatSet.YScale)
1183-
colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
1183+
colStart, rowStart, colEnd, rowEnd, x2, y2 :=
11841184
f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.OffsetX, formatSet.OffsetY, width, height)
11851185
content, cNvPrID := f.drawingParser(drawingXML)
11861186
twoCellAnchor := xdrCellAnchor{}

picture.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, he
259259
}
260260
col--
261261
row--
262-
colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
262+
colStart, rowStart, colEnd, rowEnd, x2, y2 :=
263263
f.positionObjectPixels(sheet, col, row, formatSet.OffsetX, formatSet.OffsetY, width, height)
264264
content, cNvPrID := f.drawingParser(drawingXML)
265265
twoCellAnchor := xdrCellAnchor{}

shape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
324324
width := int(float64(formatSet.Width) * formatSet.Format.XScale)
325325
height := int(float64(formatSet.Height) * formatSet.Format.YScale)
326326

327-
colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
327+
colStart, rowStart, colEnd, rowEnd, x2, y2 :=
328328
f.positionObjectPixels(sheet, colIdx, rowIdx, formatSet.Format.OffsetX, formatSet.Format.OffsetY,
329329
width, height)
330330
content, cNvPrID := f.drawingParser(drawingXML)

0 commit comments

Comments
 (0)