55//! by a vector. Spans are mostly allocated and constructed, and more rarely read or mutated.
66//! [VecMap] is thus optimized for insertion (which is just `Vec::push`), without any hashing
77//! involved. Fetching and removing a value is, on the other hand, linear time in the size of the
8- //! map.
8+ //! map. However, since meta and metrics are expected to be typically small (20ish elements or
9+ //! less), linear scan is usually still competitive with hashmap's `get`.
910
1011use serde:: ser:: { Serialize , Serializer } ;
1112use std:: borrow:: Borrow ;
@@ -18,8 +19,8 @@ use std::hash::Hash;
1819///
1920/// Duplicates are tolerated: [VecMap::insert] always appends, and [VecMap::get]/[VecMap::get_mut]
2021/// return the *last* matching entry so that later writes shadow earlier ones. This optimizes for
21- /// fast insert and construction (that might happen on the client's application hot path), avoiding
22- /// a linear scan on each insert ( or a potential costly full re-hashing with a hashmap) .
22+ /// fast insertion and construction (that might happen on the client's application hot path),
23+ /// avoiding a linear scan on each insert, or a potential full re-hashing with a hashmap.
2324/// Additionally, while overriding a metric or a meta definitively happens, it's assumed to be rare
2425/// enough so such that the size penalty of duplication is expected to be reasonable.
2526///
@@ -170,14 +171,14 @@ impl<K, V> Extend<(K, V)> for VecMap<K, V> {
170171
171172impl < K : Serialize + Eq + Hash , V : Serialize > Serialize for VecMap < K , V > {
172173 fn serialize < S : Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
173- // We pre-compute the deduped map. If deduplication is done on the fly during serialization,
174- // we can 't provide a length up front to the serializer, and the current one (rmp) will
175- // allocate an intermediate buffer defensively.
174+ // We pre-compute the deduped map. If deduplication were done on the fly during
175+ // serialization, we couldn 't provide a length up front to the serializer, and the current
176+ // one (rmp) will allocate an intermediate buffer defensively.
176177 self . 0
177178 . iter ( )
178179 . map ( |( k, v) | ( k, v) )
179180 // Since the iterator is sized, `collect()` should pre-allocate with the right capacity
180- // directly .
181+ // in one shot .
181182 . collect :: < HashMap < & K , & V > > ( )
182183 . serialize ( serializer)
183184 }
0 commit comments