Created
October 1, 2018 21:31
-
-
Save berfarah/63072d92cd212831ed4cbea8b5f47111 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
// goodbye reflect.New in Scanner.Scan | |
func (s *Scanner) Scan(src interface{}) error { | |
- s.value = reflect.New(s.Type) | |
+ // Clear out the value after a scan so we aren't holding onto references. | |
+ defer func() { s.value = reflect.Value{} }() | |
// ... | |
} | |
// and hello Scanner.Target | |
+func (s *Scanner) Target(value reflect.Value) { | |
+ s.value = value | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment