private int registerInternal(PollItem item) {
            int pos = -1;

            if (!this.freeSlots.isEmpty()) {
                // If there are free slots in our array, remove one
                // from the free list and use it.
                pos = this.freeSlots.remove();
            } else {
                if (this.next >= this.size) {
                    // It is necessary to grow the arrays.

                    // Compute new size for internal arrays.
                    int nsize = this.size + SIZE_INCREMENT;

                    // Create new internal arrays.
                    PollItem[] ns = new PollItem[nsize];
                    short[] ne = new short[nsize];
                    short[] nr = new short[nsize];

                    // Copy contents of current arrays into new arrays.
                    for (int i = 0; i < this.next; ++i) {
                        ns[i] = this.items[i];
                    }

                    // Swap internal arrays and size to new values.
                    this.size = nsize;
                    this.items = ns;
                }
                pos = this.next++;
            }

            this.items[pos] = item;
            this.used++;
            return pos;
        }