lzo: update to 2.09
[tomato.git] / release / src / router / lzo / src / lzo1b_cr.ch
blob844ce94caa417b34da50cdef1bbceb1109ce17eb
1 /* lzo1b_cr.ch -- implementation of the LZO1B compression algorithm
3    This file is part of the LZO real-time data compression library.
5    Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
6    All Rights Reserved.
8    The LZO library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of
11    the License, or (at your option) any later version.
13    The LZO library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
18    You should have received a copy of the GNU General Public License
19    along with the LZO library; see the file COPYING.
20    If not, write to the Free Software Foundation, Inc.,
21    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23    Markus F.X.J. Oberhumer
24    <markus@oberhumer.com>
25    http://www.oberhumer.com/opensource/lzo/
26  */
29 /* WARNING: this file should *not* be used by applications. It is
30    part of the implementation of the library and is subject
31    to change.
32  */
36 /***********************************************************************
37 // store the current literal run
38 ************************************************************************/
40         assert(ip < ip_end);
41         if (pd(ip,ii) > 0)
42         {
43             lzo_uint t = pd(ip,ii);
45 #if defined(LZO_HAVE_R1)
46             if (ip == r1)
47             {
48                 /* Code a context sensitive R1 match. */
49                 LZO_STATS(lzo_stats->literals += t);
50                 LZO_STATS(lzo_stats->r1_matches++);
51                 assert(t == 1);
52                 /* modify marker byte */
53                 assert((op[-2] >> M2O_BITS) == (M2_MARKER >> M2O_BITS));
54                 op[-2] &= M2O_MASK;
55                 assert((op[-2] >> M2O_BITS) == 0);
56                 /* copy 1 literal */
57                 *op++ = *ii++;
58                 r1 = ip + (M2_MIN_LEN + 1);     /* set new R1 pointer */
59             }
60             else
61 #endif
62             if (t < R0MIN)
63             {
64                 /* inline the copying of a short run */
65                 LZO_STATS(lzo_stats->literals += t);
66                 LZO_STATS(lzo_stats->lit_runs++);
67                 LZO_STATS(lzo_stats->lit_run[t]++);
68 #if defined(LZO_HAVE_M3)
69                 if (t < LZO_SIZE(8-M3O_BITS) && op == m3)
70                 {
71                 /* Code a very short literal run into the low offset bits
72                  * of the previous M3/M4 match.
73                  */
74                     LZO_STATS(lzo_stats->lit_runs_after_m3_match++);
75                     LZO_STATS(lzo_stats->lit_run_after_m3_match[t]++);
76                     assert((m3[-2] >> M3O_BITS) == 0);
77                     m3[-2] = LZO_BYTE(m3[-2] | (t << M3O_BITS));
78                 }
79                 else
80 #endif
81                 {
82                     *op++ = LZO_BYTE(t);
83                 }
84                 MEMCPY_DS(op, ii, t);
85 #if defined(LZO_HAVE_R1)
86                 r1 = ip + (M2_MIN_LEN + 1);     /* set new R1 pointer */
87 #endif
88             }
89             else if (t < R0FAST)
90             {
91                 /* inline the copying of a short R0 run */
92                 LZO_STATS(lzo_stats->literals += t);
93                 LZO_STATS(lzo_stats->r0short_runs++);
94                 *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
95                 MEMCPY_DS(op, ii, t);
96 #if defined(LZO_HAVE_R1)
97                 r1 = ip + (M2_MIN_LEN + 1);     /* set new R1 pointer */
98 #endif
99             }
100             else
101             {
102                 op = STORE_RUN(op,ii,t);
103                 ii = ip;
104             }
105         }
108         /* ii now points to the start of the current match */
109         assert(ii == ip);
112 /* vim:set ts=4 sw=4 et: */