Created
October 1, 2018 21:32
-
-
Save berfarah/05dd038c27f718dd586396c4b2284c99 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Optimization 2: Cutting out the middleman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func parseQueryRow(table *Table, rows *sql.Rows) (interface{}, error) { | |
ptr := reflect.New(table.Type) | |
elem := ptr.Elem() | |
values := make([]interface{}, len(table.Columns)) | |
- [... populate scanners slice with column.Descriptor.Scanner() ...] | |
+ for i, column := range table.Columns { | |
+ scanner := column.Descriptor.Scanner() | |
+ scanner.Target(field) | |
+ values[i] = scanner | |
+ } | |
if err := rows.Scan(values...); err != nil { | |
return nil, err | |
} | |
- for i, column := range table.Columns { | |
- scanners[i].CopyTo(elem.FieldByIndex(column.Index)) | |
- } | |
return ptr.Interface(), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment