Skip to content

Commit

Permalink
This reduces memory usage and speedup the AddComment function (qax-…
Browse files Browse the repository at this point in the history
…os#1311)

By load only once for existing comment shapes, improving performance for adding comments in the worksheet
  • Loading branch information
ee0703 authored and xuri committed Jul 11, 2023
1 parent 29cde39 commit d8b2532
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
},
},
}
// load exist comment shapes from xl/drawings/vmlDrawing%d.vml (only once)
d := f.decodeVMLDrawingReader(drawingVML)
if d != nil {
for _, v := range d.Shape {
s := xlsxShape{
ID: "_x0000_s1025",
Type: "#_x0000_t202",
Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden",
Fillcolor: "#fbf6d6",
Strokecolor: "#edeaa1",
Val: v.Val,
}
vml.Shape = append(vml.Shape, s)
}
}
}
sp := encodeShape{
Fill: &vFill{
Expand Down Expand Up @@ -222,20 +237,6 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
Strokecolor: "#edeaa1",
Val: string(s[13 : len(s)-14]),
}
d := f.decodeVMLDrawingReader(drawingVML)
if d != nil {
for _, v := range d.Shape {
s := xlsxShape{
ID: "_x0000_s1025",
Type: "#_x0000_t202",
Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden",
Fillcolor: "#fbf6d6",
Strokecolor: "#edeaa1",
Val: v.Val,
}
vml.Shape = append(vml.Shape, s)
}
}
vml.Shape = append(vml.Shape, shape)
f.VMLDrawing[drawingVML] = vml
return err
Expand Down

0 comments on commit d8b2532

Please sign in to comment.