Skip to content
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

What: add spec for array ops with []uint8 or []byte type #128

Merged
merged 2 commits into from
Apr 3, 2018

Conversation

mcspring
Copy link

Why:

  • mongodb aquires array for $in/$nin/$all ops

How:

  • encode with array for spec

@domodwyer
Copy link

Hi @mcspring

You make a really good point about the array ops and thanks for the PR (with tests!) - there's a conflict on the branch though but should be good to merge after.

Dom

szank
szank previously approved these changes Mar 26, 2018
@@ -60,6 +60,15 @@ var (
typeTimeDuration = reflect.TypeOf(time.Duration(0))
)

var (
// spec for []uint8 or []byte encoding
arrayOps = map[string]bool{
Copy link

@szank szank Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick here ( sorry! )
IIRC map[string]struct{} could be used here, and that one has an optimised lookup code when you want to only check for the presence of an element.

this would transform the map lookups to

if _, ok := arrayOps[name]; ok {
[...]
}

Which is not as clean. I'll let you make a call here. I haven't benchmarked the code, so I can't tell how much faster it is, but it is the idiomatic go way of doing things FWIW.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way will cause one more alloc, which can be avoid from previous.

Why:

  * mongodb aquires array for $in/$nin/$all ops

How:

  * encode with array for spec
@mcspring
Copy link
Author

@domodwyer synced yet.

@domodwyer
Copy link

Looks good to me - thanks @mcspring

Dom

@domodwyer domodwyer merged commit 69bef6a into globalsign:development Apr 3, 2018
@domodwyer domodwyer mentioned this pull request Apr 23, 2018
libi pushed a commit to libi/mgo that referenced this pull request Dec 1, 2022
)

Why:

  * mongodb aquires array for $in/$nin/$all ops

How:

  * encode with array for spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants