예제 #1
0
 private static unsafe void DestroyHasher(
     ref MemoryManager m, HasherHandle *handle)
 {
     if ((void *)(*handle) == null)
     {
         return;
     }
     BrotliFree(ref m, *handle);
 }
예제 #2
0
        private static unsafe void InitOrStitchToPreviousBlock(
            ref MemoryManager m, HasherHandle *handle, byte *data, size_t mask,
            BrotliEncoderParams *params_, size_t position, size_t input_size,
            bool is_last)
        {
            HasherHandle self;

            HasherSetup(ref m, handle, params_, data, position, input_size, is_last);
            self = *handle;
            Hasher h;

            if (kHashers.TryGetValue(GetHasherCommon(self)->params_.type, out h))
            {
                h.StitchToPreviousBlock(self, input_size, position, data, mask);
            }
        }
예제 #3
0
        private static unsafe void HasherSetup(ref MemoryManager m, HasherHandle *handle,
                                               BrotliEncoderParams *params_, byte *data, size_t position,
                                               size_t input_size, bool is_last)
        {
            HasherHandle  self     = null;
            HasherCommon *common   = null;
            bool          one_shot = (position == 0 && is_last);

            if ((byte *)(*handle) == null)
            {
                size_t alloc_size;
                ChooseHasher(params_, &params_->hasher);
                alloc_size = HasherSize(params_, one_shot, input_size);
                self       = BrotliAllocate(ref m, alloc_size);
                *handle = self;
                common          = GetHasherCommon(self);
                common->params_ = params_->hasher;
                Hasher h;
                if (kHashers.TryGetValue(params_->hasher.type, out h))
                {
                    h.Initialize(*handle, params_);
                }
                HasherReset(*handle);
            }

            self   = *handle;
            common = GetHasherCommon(self);
            if (!common->is_prepared_)
            {
                Hasher h;
                if (kHashers.TryGetValue(params_->hasher.type, out h))
                {
                    h.Prepare(self, one_shot, input_size, data);
                }
                if (position == 0)
                {
                    common->dict_num_lookups = 0;
                    common->dict_num_matches = 0;
                }
                common->is_prepared_ = true;
            }
        }
예제 #4
0
        /* Custom LZ77 window. */
        private static unsafe void HasherPrependCustomDictionary(
            ref MemoryManager m, HasherHandle *handle, BrotliEncoderParams *params_,
            size_t size, byte *dict)
        {
            size_t       overlap;
            size_t       i;
            HasherHandle self;

            HasherSetup(ref m, handle, params_, dict, 0, size, false);
            self = *handle;
            Hasher h;

            if (kHashers.TryGetValue(GetHasherCommon(self)->params_.type, out h))
            {
                overlap = h.StoreLookahead() - 1;
                for (i = 0; i + overlap < size; i++)
                {
                    h.Store(self, dict, ~(size_t)0, i);
                }
            }
        }