-
Notifications
You must be signed in to change notification settings - Fork 148
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
ByteStream consumer can write to interface{} #273
Conversation
cc: @danny-cheung |
@casualjim @youyuanwu I am interested by your feedback on this approach, as it doesn't make sense to adopt it for just the Bytestream Consumer. Please let me know what are your thoughts. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #273 +/- ##
==========================================
+ Coverage 80.83% 80.99% +0.15%
==========================================
Files 44 44
Lines 3366 3394 +28
==========================================
+ Hits 2721 2749 +28
Misses 535 535
Partials 110 110
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
d2cdb7c
to
e1af0d1
Compare
e1af0d1
to
a7fcf73
Compare
@casualjim I'd like to add a little more test work on that one. I'd like to benchmark a bit to figure out the actual savings with not entering the "reflected" code path. If this is proves to be a sound pattern, I'll generalize in a follow-up pattern, e.g. fixing #263 |
a7fcf73
to
e827593
Compare
|
e827593
to
d9f89fe
Compare
@casualjim the benchmark demonstrates that I was wrong ... There is actually no material benefit from favoring type a switch over reflect (when done correctly). The benchmark shows that the reflection path is actually quite efficient and that the reflect.Value is not allocated on the heap. Therefore, I am going to simplify this and remove the redundant cases. |
* fix(ByteStreamConsumer): may now write into an interface which underlying type is []byte or string. * feat(ByteStreamConsumer): added support to io.ReaderFrom, preferred over io.Writer if available * feat(ByteStreamProducer): added support to io.WriterTo, preferred over io.Reader if available * refact(ByteStreamProducer): removed redundant case "string" and preferred the more general reflected case (supports aliased strings) * test: refactored ByteStream tests * test: added benchmark for bytestream.Consume * fixes go-openapi#167 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
d9f89fe
to
0a0b04d
Compare
This is a follow-up on go-openapi#273. I realized that a few typos escaped my review on docstrings and that some misnomers for variables in tests made the tests difficult to read (e.g. rdr for a Writer...). Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This is a follow-up on go-openapi#273. I realized that a few typos escaped my review on docstrings and that some misnomers for variables in tests made the tests difficult to read (e.g. rdr for a Writer...). Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This is a follow-up on #273. I realized that a few typos escaped my review on docstrings and that some misnomers for variables in tests made the tests difficult to read (e.g. rdr for a Writer...). Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
ByteStream consumer can write to interface{}
fix(ByteStreamConsumer): may now write into an interface which
underlying type is []byte or string.
feat(ByteStreamConsumer): added support to io.ReaderFrom, preferred
over io.Writer if available
feat(ByteStreamProducer): added support to io.WriterTo, preferred
over io.Reader if available
refact(ByteStreamProducer): removed redundant case "string" and preferred
the more general reflected case (supports aliased strings)
test: refactored ByteStream tests
test: added benchmark for bytestream.Consume
fixes ByteStreamConsumer can't write to interface{} #167
Signed-off-by: Frederic BIDON fredbi@yahoo.com