1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-11 02:50:27 +08:00

reduce unsafe

This commit is contained in:
源文雨
2023-03-04 21:31:03 +08:00
parent 1e227341ee
commit ff131af5fa
3 changed files with 13 additions and 23 deletions

View File

@@ -20,8 +20,6 @@
package docx
import "unsafe"
// AddTable add a new table to body by col*row
//
// unit: twips (1/20 point)
@@ -42,7 +40,7 @@ func (f *Docx) AddTable(row int, col int) *WTable {
TableCells: cells,
}
}
f.Document.Body.Items = append(f.Document.Body.Items, &WTable{
tbl := &WTable{
TableProperties: &WTableProperties{
Width: &WTableWidth{Type: "auto"},
TableBorders: &WTableBorders{
@@ -59,11 +57,9 @@ func (f *Docx) AddTable(row int, col int) *WTable {
},
TableGrid: &WTableGrid{},
TableRows: trs,
})
t := f.Document.Body.Items[len(f.Document.Body.Items)-1]
return *(**WTable)(unsafe.Add(unsafe.Pointer(&t), unsafe.Sizeof(uintptr(0))))
}
f.Document.Body.Items = append(f.Document.Body.Items, tbl)
return tbl
}
// AddTableTwips add a new table to body by height and width
@@ -99,7 +95,7 @@ func (f *Docx) AddTableTwips(rowHeights []int64, colWidths []int64) *WTable {
}
}
}
f.Document.Body.Items = append(f.Document.Body.Items, &WTable{
tbl := &WTable{
TableProperties: &WTableProperties{
Width: &WTableWidth{Type: "auto"},
TableBorders: &WTableBorders{
@@ -118,11 +114,9 @@ func (f *Docx) AddTableTwips(rowHeights []int64, colWidths []int64) *WTable {
GridCols: grids,
},
TableRows: trs,
})
t := f.Document.Body.Items[len(f.Document.Body.Items)-1]
return *(**WTable)(unsafe.Add(unsafe.Pointer(&t), unsafe.Sizeof(uintptr(0))))
}
f.Document.Body.Items = append(f.Document.Body.Items, tbl)
return tbl
}
// Justification allows to set table's horizonal alignment