/**
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package rx.operators;

import java.util.Deque;
import java.util.LinkedList;

import rx.Observable.Operator;
import rx.Subscriber;

/**
 * Bypasses a specified number of elements at the end of an observable sequence.
 */
public class OperatorSkipLast<T> implements Operator<T, T> {

    private final int count;

    public OperatorSkipLast(int count) {
        if (count < 0) {
            throw new IndexOutOfBoundsException("count could not be negative");
        }
        this.count = count;
    }

    @Override
    public Subscriber<? super T> call(final Subscriber<? super T> subscriber) {
        return new Subscriber<T>(subscriber) {
            /**
             * Store the last count elements until now.
             */
            private final Deque<T> deque = new LinkedList<T>();

            @Override
            public void onCompleted() {
                subscriber.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                subscriber.onError(e);
            }

            @Override
            public void onNext(T value) {
                if (count == 0) {
                    // If count == 0, we do not need to put value into deque
                    // and remove it at once. We can emit the value
                    // directly.
                    subscriber.onNext(value);
                    return;
                }
                deque.offerLast(value);
                if (deque.size() > count) {
                    // Now deque has count + 1 elements, so the first
                    // element in the deque definitely does not belong
                    // to the last count elements of the source
                    // sequence. We can emit it now.
                    subscriber.onNext(deque.removeFirst());
                }
            }

        };
    }

}

@@ -627,16 +627,21 @@
 va.util.
+Array
 Deque;%0Ai
@@ -656,26 +656,21 @@
 va.util.
-LinkedList
+Deque
 ;%0A%0Aimpor
@@ -1223,32 +1223,114 @@
 %3E(subscriber) %7B%0A
+%0A            private final NotificationLite%3CT%3E on = NotificationLite.instance();%0A%0A
             /**%0A
@@ -1433,17 +1433,22 @@
 l Deque%3C
-T
+Object
 %3E deque 
@@ -1457,20 +1457,25 @@
 new 
-LinkedList%3CT
+ArrayDeque%3CObject
 %3E();
@@ -2090,48 +2090,8 @@
   %7D%0A
-                deque.offerLast(value);%0A
     
@@ -2119,17 +2119,18 @@
 .size() 
-%3E
+==
  count) 
@@ -2155,323 +2155,127 @@
     
-// Now deque has count + 1 elements, so the first%0A                    // element in the deque definitely does not belong%0A                    // to the last count elements of the source%0A                    // sequence. We can emit it now.%0A                    subscriber.onNext(deque.removeFirst());%0A                %7D
+subscriber.onNext(on.getValue(deque.removeFirst()));%0A                %7D%0A                deque.offerLast(on.next(value));
 %0A   

Replace LinkedList with ArrayDeque