Coverage Report

Created: 2024-05-21 06:11

/src/lzo-2.10/src/lzo1c_cc.c
Line
Count
Source (jump to first uncovered line)
1
/* lzo1c_cc.c -- LZO1C compression internal entry point
2
3
   This file is part of the LZO real-time data compression library.
4
5
   Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6
   All Rights Reserved.
7
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.
12
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.
17
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.
22
23
   Markus F.X.J. Oberhumer
24
   <markus@oberhumer.com>
25
   http://www.oberhumer.com/opensource/lzo/
26
 */
27
28
29
#define LZO_NEED_DICT_H 1
30
#include "config1c.h"
31
32
33
/***********************************************************************
34
// compression internal entry point.
35
************************************************************************/
36
37
LZO_LOCAL_IMPL(int)
38
_lzo1c_do_compress ( const lzo_bytep in,  lzo_uint  in_len,
39
                           lzo_bytep out, lzo_uintp out_len,
40
                           lzo_voidp wrkmem,
41
                           lzo_compress_t func )
42
1.76k
{
43
1.76k
    int r;
44
#if defined(LZO_TEST_COMPRESS_OVERRUN)
45
    lzo_uint avail_out = *out_len;
46
#endif
47
48
49
#if (LZO_COLLECT_STATS)
50
    _lzo1c_stats_init(lzo_stats);
51
    lzo_stats->in_len = in_len;
52
#endif
53
54
55
    /* don't try to compress a block that's too short */
56
1.76k
    if (in_len == 0)
57
4
    {
58
4
        *out_len = 0;
59
4
        r = LZO_E_OK;
60
4
    }
61
1.75k
    else if (in_len <= MIN_LOOKAHEAD + 1)
62
7
    {
63
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
64
        *out_len = 0;
65
        r = LZO_E_NOT_COMPRESSIBLE;
66
#else
67
7
        *out_len = pd(STORE_RUN(out,in,in_len), out);
68
7
        r = (*out_len > in_len) ? LZO_E_OK : LZO_E_ERROR;
69
7
#endif
70
7
    }
71
1.75k
    else
72
1.75k
        r = func(in,in_len,out,out_len,wrkmem);
73
74
75
1.76k
#if defined(LZO_EOF_CODE)
76
#if defined(LZO_TEST_COMPRESS_OVERRUN)
77
    if (r == LZO_E_OK && avail_out - *out_len < 3)
78
        r = LZO_E_COMPRESS_OVERRUN;
79
#endif
80
1.76k
    if (r == LZO_E_OK)
81
1.76k
    {
82
1.76k
        lzo_bytep op = out + *out_len;
83
1.76k
        op[0] = M3_MARKER | 1;
84
1.76k
        op[1] = 0;
85
1.76k
        op[2] = 0;
86
1.76k
        *out_len += 3;
87
1.76k
    }
88
1.76k
#endif
89
90
91
#if (LZO_COLLECT_STATS)
92
    lzo_stats->out_len = *out_len;
93
    lzo_stats->match_bytes =
94
       1 * lzo_stats->m1_matches + 2 * lzo_stats->m2_matches +
95
       3 * lzo_stats->m3_matches + 4 * lzo_stats->m4_matches;
96
    _lzo1c_stats_calc(lzo_stats);
97
#endif
98
99
1.76k
    return r;
100
1.76k
}
101
102
103
/***********************************************************************
104
// note: this is not thread safe, but as it is used for finetuning only
105
//       we don't care
106
************************************************************************/
107
108
#undef lzo_stats
109
/* lzo_stats_t is still defined */
110
111
112
#if (LZO_COLLECT_STATS)
113
114
static lzo_stats_t lzo_statistics;
115
lzo_stats_t * const lzo1c_stats = &lzo_statistics;
116
117
118
void _lzo1c_stats_init(lzo_stats_t *lzo_stats)
119
{
120
    lzo_memset(lzo_stats,0,sizeof(*lzo_stats));
121
}
122
123
124
void _lzo1c_stats_calc(lzo_stats_t *lzo_stats)
125
{
126
    lzo_stats->matches =
127
       lzo_stats->m1_matches + lzo_stats->m2_matches +
128
       lzo_stats->m3_matches + lzo_stats->m4_matches;
129
130
    lzo_stats->literal_overhead = lzo_stats->lit_runs +
131
       2 * (lzo_stats->r0short_runs + lzo_stats->r0fast_runs +
132
            lzo_stats->r0long_runs);
133
    lzo_stats->literal_bytes = lzo_stats->literals +
134
       lzo_stats->literal_overhead;
135
136
#if 0
137
    assert(lzo_stats->match_bytes + lzo_stats->literal_bytes ==
138
       lzo_stats->out_len);
139
#endif
140
141
    lzo_stats->m2_matches -= lzo_stats->r1_matches;
142
    lzo_stats->m2_match[M2_MIN_LEN] -= lzo_stats->r1_matches;
143
144
    if (lzo_stats->literals > 0)
145
        lzo_stats->literal_overhead_percent =
146
           100.0 * lzo_stats->literal_overhead / lzo_stats->literals;
147
}
148
149
150
#endif
151
152
153
/* vim:set ts=4 sw=4 et: */