Skip to content

Commit 3e9e2ff

Browse files
committed
reduce iteration
1 parent d6975fe commit 3e9e2ff

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

dump.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,29 +320,31 @@ func (table *table) initColumnData() error {
320320
scans[i] = &info[i]
321321
}
322322

323+
fieldIndex, extraIndex := -1, -1
324+
for i, col := range cols {
325+
switch col {
326+
case "Field", "field":
327+
fieldIndex = i
328+
case "Extra", "extra":
329+
extraIndex = i
330+
}
331+
if fieldIndex > 0 && extraIndex > 0 {
332+
break
333+
}
334+
}
335+
if fieldIndex <= 0 || extraIndex < 0 {
336+
return errors.New("database column information is malformed")
337+
}
338+
323339
var result []string
324340
for colInfo.Next() {
325341
// Read into the pointers to the info marker
326342
if err := colInfo.Scan(scans...); err != nil {
327343
return err
328344
}
329345

330-
// Find the the fields we care about
331-
var field, extra *sql.NullString
332-
for i, col := range cols {
333-
switch col {
334-
case "Field", "field":
335-
field = &info[i]
336-
case "Extra", "extra":
337-
extra = &info[i]
338-
}
339-
if field != nil && extra != nil {
340-
break
341-
}
342-
}
343-
344-
if !extra.Valid || !strings.Contains(extra.String, "VIRTUAL") {
345-
result = append(result, field.String)
346+
if !info[extraIndex].Valid || !strings.Contains(info[extraIndex].String, "VIRTUAL") {
347+
result = append(result, info[fieldIndex].String)
346348
}
347349
}
348350
table.cols = result

0 commit comments

Comments
 (0)