Path: blob/master/thirdparty/graphite/src/inc/Compression.h
9906 views
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later1// Copyright 2015, SIL International, All rights reserved.234#pragma once56#include <cassert>7#include <cstddef>8#include <cstring>910namespace11{1213#if defined(_MSC_VER)14typedef unsigned __int8 u8;15typedef unsigned __int16 u16;16typedef unsigned __int32 u32;17typedef unsigned __int64 u64;18#else19#include <stdint.h>20typedef uint8_t u8;21typedef uint16_t u16;22typedef uint32_t u32;23typedef uint64_t u64;24#endif2526ptrdiff_t const MINMATCH = 4,27LASTLITERALS = 5,28MINCODA = LASTLITERALS+1,29MINSRCSIZE = 13;3031template<int S>32inline33void unaligned_copy(void * d, void const * s) {34::memcpy(d, s, S);35}3637inline38size_t align(size_t p) {39return (p + sizeof(unsigned long)-1) & ~(sizeof(unsigned long)-1);40}4142inline43u8 * safe_copy(u8 * d, u8 const * s, size_t n) {44while (n--) *d++ = *s++;45return d;46}4748inline49u8 * overrun_copy(u8 * d, u8 const * s, size_t n) {50size_t const WS = sizeof(unsigned long);51u8 const * e = s + n;52do53{54unaligned_copy<WS>(d, s);55d += WS;56s += WS;57}58while (s < e);59d-=(s-e);6061return d;62}636465inline66u8 * fast_copy(u8 * d, u8 const * s, size_t n) {67size_t const WS = sizeof(unsigned long);68size_t wn = n/WS;69while (wn--)70{71unaligned_copy<WS>(d, s);72d += WS;73s += WS;74}75n &= WS-1;76return safe_copy(d, s, n);77}787980} // end of anonymous namespace818283