harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enh <...@google.com>
Subject Re: [classlib] BufferedReader and FileInputStream.available()
Date Thu, 05 Nov 2009 18:45:37 GMT
On Wed, Nov 4, 2009 at 23:07, Regis <xu.regis@gmail.com> wrote:
> Mark Hindess wrote:
>>
>> In message <4AF0DC18.1000504@gmail.com>, Regis writes:
>>
>> Regis, these are really two different issues so lets treat them as
>> such.  I actually think fixing the /proc reading is better done in
>> the java code.  I've attached a patch that just catches and ignores
>> the IOException from the available call.  I think this is reasonable
>> since if the exception was "real" then the read will fail if a similar
>> exception.  In fact, since the user is doing a read call, having the
>> exception thrown by the read is more in keeping with the expectations of
>> the user than having an exception thrown by the available call.
>>
>
> Thanks Mark, I ran luni tests with your patch, no regression found, I'll
> leave patch to you to apply :)
>
> invoking in.available before read is a little overhead, in the worst case,
> one read need four system calls, three seek and one read. Actually the
> condition
>
> if ((in.available() == 0) && (out.position() > offset))
>
> it's only for tty file, for normal file it's not necessary. It's better if
> we can remove the check for normal file, but I have no idea how to do this.

isatty(3). for the price of one JNI call at construction and a boolean
field to record the result, you could avoid any later calls.

in the meantime, i wondered also whether it's worth swapping the two
conjuncts in the if, since the latter is essentially free while the
former is expensive. (i've no idea how often the cheap conjunct is
false, though.)

 --elliott

>> Making the available call (or part of it) a single native method call
>> is a separate issue.
>>
>> Regards,
>>  Mark.
>>
>>
>>
>
>
> --
> Best Regards,
> Regis.
>



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/

Mime
View raw message