| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "sync" | 9 "sync" |
| 10 "time" | 10 "time" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return nil | 114 return nil |
| 115 }) | 115 }) |
| 116 if err != nil { | 116 if err != nil { |
| 117 return err | 117 return err |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Punt all of the records upstream. We copy the data to prevent the | 120 // Punt all of the records upstream. We copy the data to prevent the |
| 121 // callback from accidentally mutating it. We reuse the data buffer to t
ry | 121 // callback from accidentally mutating it. We reuse the data buffer to t
ry |
| 122 // and catch errors when the callback retains the data. | 122 // and catch errors when the callback retains the data. |
| 123 for _, r := range recs { | 123 for _, r := range recs { |
| 124 » » dataCopy := make([]byte, len(r.data)) | 124 » » var dataCopy []byte |
| 125 » » copy(dataCopy, r.data) | 125 » » if !req.KeysOnly { |
| 126 » » » dataCopy = make([]byte, len(r.data)) |
| 127 » » » copy(dataCopy, r.data) |
| 128 » » } |
| 126 if !cb(r.index, dataCopy) { | 129 if !cb(r.index, dataCopy) { |
| 127 break | 130 break |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 | 133 |
| 131 return nil | 134 return nil |
| 132 } | 135 } |
| 133 | 136 |
| 134 // Tail implements storage.Storage. | 137 // Tail implements storage.Storage. |
| 135 func (s *Storage) Tail(p types.StreamPath) ([]byte, types.MessageIndex, error) { | 138 func (s *Storage) Tail(p types.StreamPath) ([]byte, types.MessageIndex, error) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 199 } |
| 197 | 200 |
| 198 if s.streams == nil { | 201 if s.streams == nil { |
| 199 s.streams = map[types.StreamPath]*logStream{} | 202 s.streams = map[types.StreamPath]*logStream{} |
| 200 } | 203 } |
| 201 s.streams[p] = ls | 204 s.streams[p] = ls |
| 202 } | 205 } |
| 203 | 206 |
| 204 return ls | 207 return ls |
| 205 } | 208 } |
| OLD | NEW |