-
-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid converting BTreeMap to Vec in TantivyDocument::add_object. #2369
Conversation
@adamreichold it won't compile. |
1f77307
to
4826e74
Compare
Yes, because a sequence of key-value pairs cannot directly be deserialized from a map. I added a thin wrapper to make that adjustment which avoids the overhead of the associative data structures, but keeps the convenience during deserialization. |
@@ -150,7 +151,7 @@ impl TantivyDocument { | |||
} | |||
|
|||
/// Add a dynamic object field | |||
pub fn add_object(&mut self, field: Field, object: BTreeMap<String, OwnedValue>) { | |||
pub fn add_object(&mut self, field: Field, FlatObject(object): FlatObject) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that seems like a worse API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please expand on worse in what way or rather what you would prefer?
It definitely adds a bit of ceremony for the wrapper type, but it does avoid the unnecessary conversion for example in the unit tests here. Would you prefer some kind of implicit conversion via generics and trait bounds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTreeMap
is a well know data structure for objects, while FlatObject
would require some digging on how to convert into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about any impl IntoIterator<Item=(String, OwnedValue>)>
I don't quite understand the motivation for this PR. @adamreichold ? |
|
4826e74
to
9795deb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_object is a convenience function, you can now add anything that implements Value
Agreed. I was somewhat mechanically rebasing my branches and did not review all of the API changes implied by |
For the next breaking release when the immediate issues with 0.22.x are resolved.