return immediately when matched for efficiency (#1049)

pull/2/head
Sean Liang 3 years ago committed by GitHub
parent 08ad10f68e
commit 32548a6cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -325,6 +325,7 @@ func (f *File) GetActiveSheetIndex() (index int) {
for idx, sheet := range wb.Sheets.Sheet { for idx, sheet := range wb.Sheets.Sheet {
if sheet.SheetID == sheetID { if sheet.SheetID == sheetID {
index = idx index = idx
return
} }
} }
} }
@ -377,6 +378,7 @@ func (f *File) GetSheetName(index int) (name string) {
for idx, sheet := range f.GetSheetList() { for idx, sheet := range f.GetSheetList() {
if idx == index { if idx == index {
name = sheet name = sheet
return
} }
} }
return return
@ -386,13 +388,12 @@ func (f *File) GetSheetName(index int) (name string) {
// given sheet name. If given worksheet name is invalid, will return an // given sheet name. If given worksheet name is invalid, will return an
// integer type value -1. // integer type value -1.
func (f *File) getSheetID(name string) int { func (f *File) getSheetID(name string) int {
var ID = -1
for sheetID, sheet := range f.GetSheetMap() { for sheetID, sheet := range f.GetSheetMap() {
if sheet == trimSheetName(name) { if sheet == trimSheetName(name) {
ID = sheetID return sheetID
} }
} }
return ID return -1
} }
// GetSheetIndex provides a function to get a sheet index of the workbook by // GetSheetIndex provides a function to get a sheet index of the workbook by
@ -400,13 +401,12 @@ func (f *File) getSheetID(name string) int {
// sheet name is invalid or sheet doesn't exist, it will return an integer // sheet name is invalid or sheet doesn't exist, it will return an integer
// type value -1. // type value -1.
func (f *File) GetSheetIndex(name string) int { func (f *File) GetSheetIndex(name string) int {
var idx = -1
for index, sheet := range f.GetSheetList() { for index, sheet := range f.GetSheetList() {
if strings.EqualFold(sheet, trimSheetName(name)) { if strings.EqualFold(sheet, trimSheetName(name)) {
idx = index return index
} }
} }
return idx return -1
} }
// GetSheetMap provides a function to get worksheets, chart sheets, dialog // GetSheetMap provides a function to get worksheets, chart sheets, dialog

Loading…
Cancel
Save