From b8ceaf7bf61daecad8717abec90a8e0badb64806 Mon Sep 17 00:00:00 2001 From: EE Date: Wed, 10 Aug 2022 10:35:33 +0800 Subject: [PATCH] This reduces memory usage and speedup the `AddComment` function (#1311) By load only once for existing comment shapes, improving performance for adding comments in the worksheet --- comment.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/comment.go b/comment.go index 23f1079ad0..03b12155ec 100644 --- a/comment.go +++ b/comment.go @@ -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{ @@ -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