harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lang Yang <yangl...@gmail.com>
Subject Re: [classlib][imageio]PositionStack
Date Mon, 09 Aug 2010 00:54:33 GMT
Never mind, I think I can just cast int to long, instead of creating a new
int stack.

On Sun, Aug 8, 2010 at 8:46 PM, Lang Yang <yanglang@gmail.com> wrote:

> Hello Alexey,
>
> Thanks for the explanation. It happens that an int stack is also needed. It
> just looks a little bit redundant to have two almost the same classes at
> here though, the only difference is the datetype, one is long, the other one
> is int ;)
>
> Regards,
>
> Lang
>
> On Fri, Aug 6, 2010 at 4:38 AM, Alexey Petrenko <
> alexey.a.petrenko@gmail.com> wrote:
>
>> I see at least two reasons: this class is not synchronized and it
>> works with primitive types instead of objects.
>> So it can be a bit faster on certain circumstances...
>>
>> Thanks.
>>
>> Alexey
>>
>> 2010/8/6 Lang Yang <yanglang@gmail.com>:
>> > Hello guys,
>> >
>> > I was reviewing ImageIO, and found this class:
>> >
>> > javax.imageio.stream.ImageInputStreamImpl:
>> >
>> > private static class PositionStack {
>> > private static final int SIZE = 10;
>> >
>> > private long[] values = new long[SIZE];
>> > private int pos = 0;
>> >
>> > void push(long v) {
>> > if (pos >= values.length) {
>> > ensure(pos + 1);
>> > }
>> > values[pos++] = v;
>> > }
>> >
>> > long pop() {
>> > return values[--pos];
>> > }
>> >
>> > boolean isEmpty() {
>> > return pos == 0;
>> > }
>> >
>> > private void ensure(int size) {
>> > long[] arr = new long[Math.max(2 * values.length, size)];
>> > System.arraycopy(values, 0, arr, 0, values.length);
>> > values = arr;
>> > }
>> > }
>> >
>> > Essentially, it's just a stack, but why do we create this class rather
>> than
>> > just use the standard Stack<Long> class?
>> >
>> > Regards,
>> >
>> > Lang
>> >
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message