System.util.zlib.Deflate.fill_window C# (CSharp) Méthode

fill_window() private méthode

private fill_window ( ) : void
Résultat void
        internal void fill_window(){
            int n, m;
            int p;
            int more;    // Amount of free space at the end of the window.

            do{
                more = (window_size-lookahead-strstart);

                // Deal with !@#$% 64K limit:
                if(more==0 && strstart==0 && lookahead==0){
                    more = w_size;
                } 
                else if(more==-1) {
                    // Very unlikely, but possible on 16 bit machine if strstart == 0
                    // and lookahead == 1 (input done one byte at time)
                    more--;

                    // If the window is almost full and there is insufficient lookahead,
                    // move the upper half to the lower one to make room in the upper half.
                }
                else if(strstart >= w_size+ w_size-MIN_LOOKAHEAD) {
                    System.Array.Copy(window, w_size, window, 0, w_size);
                    match_start-=w_size;
                    strstart-=w_size; // we now have strstart >= MAX_DIST
                    block_start-=w_size;

                    // Slide the hash table (could be avoided with 32 bit values
                    // at the expense of memory usage). We slide even when level == 0
                    // to keep the hash table consistent if we switch back to level > 0
                    // later. (Using level 0 permanently is not an optimal usage of
                    // zlib, so we don't care about this pathological case.)

                    n = hash_size;
                    p=n;
                    do {
                        m = (head[--p]&0xffff);
                        head[p]=(short)(m>=w_size ? (m-w_size) : 0);
                    }
                    while (--n != 0);

                    n = w_size;
                    p = n;
                    do {
                        m = (prev[--p]&0xffff);
                        prev[p] = (short)(m >= w_size ? (m-w_size) : 0);
                        // If n is not on any hash chain, prev[n] is garbage but
                        // its value will never be used.
                    }
                    while (--n!=0);
                    more += w_size;
                }

                if (strm.avail_in == 0) return;

                // If there was no sliding:
                //    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
                //    more == window_size - lookahead - strstart
                // => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
                // => more >= window_size - 2*WSIZE + 2
                // In the BIG_MEM or MMAP case (not yet supported),
                //   window_size == input_size + MIN_LOOKAHEAD  &&
                //   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
                // Otherwise, window_size == 2*WSIZE so more >= 2.
                // If there was sliding, more >= WSIZE. So in all cases, more >= 2.

                n = strm.read_buf(window, strstart + lookahead, more);
                lookahead += n;

                // Initialize the hash value now that we have some input:
                if(lookahead >= MIN_MATCH) {
                    ins_h = window[strstart]&0xff;
                    ins_h=(((ins_h)<<hash_shift)^(window[strstart+1]&0xff))&hash_mask;
                }
                // If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
                // but this is not important since only literal bytes will be emitted.
            }
            while (lookahead < MIN_LOOKAHEAD && strm.avail_in != 0);
        }