https://codereview.appspot.com/7300071/diff/1/include/core/SkStream.h File include/core/SkStream.h (right): https://codereview.appspot.com/7300071/diff/1/include/core/SkStream.h#newcode99 include/core/SkStream.h:99: * Create a new SkData from the stream contents. ...
11 years, 11 months ago
(2013-02-08 19:29:27 UTC)
#1
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp File src/core/SkStream.cpp (right): https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp#newcode109 src/core/SkStream.cpp:109: } a-b // b+= c raises a red flag ...
11 years, 11 months ago
(2013-02-08 19:45:28 UTC)
#2
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp File src/core/SkStream.cpp (right): https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp#newcode109 src/core/SkStream.cpp:109: } I'd be curious to know what the big ...
11 years, 11 months ago
(2013-02-08 19:55:45 UTC)
#3
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp
File src/core/SkStream.cpp (right):
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp#newcode109
src/core/SkStream.cpp:109: }
I'd be curious to know what the big red flag is about exactly (performance?
opportunity for errors to sneak in?). At any rate, does this look better?
(My main concern is still whether we want to add this to common code at all; it
just seems a shame for everyone to reinvent this wheel.)
On 2013/02/08 19:45:28, caryclark1 wrote:
> a-b // b+= c raises a red flag for me. What about:
>
> size_t bytesRemaining = maxBytes;
> while (bytesRemaining <= maxBytes) {
> size_t bytesReadThisTime = this->read(bufPtr, bytesRemaining);
> ...
> bytesRemaining -= bytesReadThisTime;
> }
>
> or better:
>
> do {
> ...
> } while (bytesRemaining < maxBytes);
>
Not sure about the read-until logic here. Maybe its correct, but none of the other ...
11 years, 11 months ago
(2013-02-08 19:57:19 UTC)
#4
Not sure about the read-until logic here. Maybe its correct, but none of the
other methods or callers use SkStream in this fashion (afaik).
We have getLength() already, which returns the total size of the stream. Do we
need this max-bytes parameter at all? What is the current use-case that is
prompting us to add a new public API?
On 2013/02/08 19:57:19, reed1 wrote: > Not sure about the read-until logic here. Maybe its ...
11 years, 11 months ago
(2013-02-08 20:08:12 UTC)
#5
On 2013/02/08 19:57:19, reed1 wrote:
> Not sure about the read-until logic here. Maybe its correct, but none of the
> other methods or callers use SkStream in this fashion (afaik).
>
> We have getLength() already, which returns the total size of the stream. Do we
> need this max-bytes parameter at all? What is the current use-case that is
> prompting us to add a new public API?
The use case is my desire to read an entire file into a single contiguous
buffer. We've had an email thread going about that, and the tenor seems to be
"everyone who needs to do that writes something like this". So I figure it
would be good to put that routine somewhere for common use.
I don't so much care where that common place would be... I'm open to
suggestions.
In terms of implementation, the root of the problem is: it's not clear (to me)
whether SkStream::read() guarantees that it will read as many bytes as possible
before returning. The documentation doesn't say, and I could certainly imagine
cases where an implementation would return partial results for its own
convenience.
So, it's not clear to me that the existing SkStream::readData() would always
read the entire blob the caller wanted (like if the 32-bit length field said 10
megabytes, and read() only returned a megabyte at a time).
> In terms of implementation, the root of the problem is: it's not clear (to ...
11 years, 11 months ago
(2013-02-08 20:09:43 UTC)
#6
> In terms of implementation, the root of the problem is: it's not clear (to me)
> whether SkStream::read() guarantees that it will read as many bytes as
possible
> before returning.
If we are willing to state that all implementations of SkStream::read() already
read as many bytes as possible from the stream, then the implementation of
ReadEntireFileIntoSkData would be much simpler, and perhaps we could put it in
utils somewhere?
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp File src/core/SkStream.cpp (right): https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp#newcode109 src/core/SkStream.cpp:109: } On 2013/02/08 19:55:45, epoger wrote: > I'd be ...
11 years, 11 months ago
(2013-02-08 20:39:29 UTC)
#8
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp
File src/core/SkStream.cpp (right):
https://codereview.appspot.com/7300071/diff/1/src/core/SkStream.cpp#newcode109
src/core/SkStream.cpp:109: }
On 2013/02/08 19:55:45, epoger wrote:
> I'd be curious to know what the big red flag is about exactly (performance?
> opportunity for errors to sneak in?).
Clarity.
>At any rate, does this look better?
I guess it's all a moot point until the question is answered about if/when the
loop is actually required.
>
> (My main concern is still whether we want to add this to common code at all;
it
> just seems a shame for everyone to reinvent this wheel.)
>
> On 2013/02/08 19:45:28, caryclark1 wrote:
> > a-b // b+= c raises a red flag for me. What about:
> >
> > size_t bytesRemaining = maxBytes;
> > while (bytesRemaining <= maxBytes) {
> > size_t bytesReadThisTime = this->read(bufPtr, bytesRemaining);
> > ...
> > bytesRemaining -= bytesReadThisTime;
> > }
> >
> > or better:
> >
> > do {
> > ...
> > } while (bytesRemaining < maxBytes);
> >
>
I don't think any of our streams support this async model (correct me if I'm ...
11 years, 10 months ago
(2013-03-15 20:28:49 UTC)
#9
I don't think any of our streams support this async model (correct me if I'm
wrong).
stream->read(buffer, len)
will *always* block until either the request is met, or it fails (returning some
value less than len). In all of the other call-sites, we don't loop, and will
just report an error if the first call to read() returned fewer than expected
bytes.
Issue 7300071: Add SkStream::readIntoSkData()
Created 11 years, 11 months ago by epoger
Modified 11 years, 10 months ago
Reviewers: reed1, caryclark1
Base URL: http://skia.googlecode.com/svn/trunk/
Comments: 7