1
1
/* ----------
2
2
* lztext.c -
3
3
*
4
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.1 1999/11/17 21:21:50 wieck Exp $
4
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.2 1999/11/17 22:18:45 wieck Exp $
5
5
*
6
6
* Text type with internal LZ compressed representation. Uses the
7
7
* standard PostgreSQL compression method.
8
+ *
9
+ * This code requires that the LZ compressor found in pg_lzcompress
10
+ * codes a usable VARSIZE word at the beginning of the output buffer.
8
11
* ----------
9
12
*/
10
13
@@ -42,7 +45,7 @@ lztextin(char *str)
42
45
return NULL ;
43
46
44
47
/* ----------
45
- * Determine input size and eventually tuple size
48
+ * Determine input size and maximum output Datum size
46
49
* ----------
47
50
*/
48
51
rawsize = strlen (str );
@@ -56,8 +59,9 @@ lztextin(char *str)
56
59
pglz_compress (str , rawsize , tmp , NULL );
57
60
58
61
/* ----------
59
- * If we miss less than x% bytes at the end of the temp value,
60
- * so be it. Therefore we save a memcpy().
62
+ * If we miss less than 25% bytes at the end of the temp value,
63
+ * so be it. Therefore we save a palloc()/memcpy()/pfree()
64
+ * sequence.
61
65
* ----------
62
66
*/
63
67
if (tmp_size - tmp -> varsize < 256 ||
@@ -141,7 +145,7 @@ lztextlen(lztext *lz)
141
145
* without multibyte support, it's the remembered rawsize
142
146
* ----------
143
147
*/
144
- return lz -> rawsize ;
148
+ return PGLZ_RAW_SIZE ( lz ) ;
145
149
}
146
150
147
151
@@ -166,7 +170,7 @@ lztextoctetlen(lztext *lz)
166
170
* Return the varsize minus the VARSIZE field itself.
167
171
* ----------
168
172
*/
169
- return lz -> varsize - sizeof ( int32 ) ;
173
+ return VARSIZE ( lz ) - VARHDRSZ ;
170
174
}
171
175
172
176
@@ -208,8 +212,9 @@ text_lztext(text *txt)
208
212
pglz_compress (str , rawsize , tmp , NULL );
209
213
210
214
/* ----------
211
- * If we miss less than x% bytes at the end of the temp value,
212
- * so be it. Therefore we save a memcpy().
215
+ * If we miss less than 25% bytes at the end of the temp value,
216
+ * so be it. Therefore we save a palloc()/memcpy()/pfree()
217
+ * sequence.
213
218
* ----------
214
219
*/
215
220
if (tmp_size - tmp -> varsize < 256 ||
@@ -250,15 +255,15 @@ lztext_text(lztext *lz)
250
255
* Allocate and initialize the text result
251
256
* ----------
252
257
*/
253
- result = (text * ) palloc (lz -> rawsize + VARHDRSZ + 1 );
258
+ result = (text * ) palloc (PGLZ_RAW_SIZE ( lz ) + VARHDRSZ + 1 );
254
259
VARSIZE (result ) = lz -> rawsize + VARHDRSZ ;
255
260
256
261
/* ----------
257
262
* Decompress directly into the text data area.
258
263
* ----------
259
264
*/
260
- pglz_decompress (lz , VARDATA (result ));
261
265
VARDATA (result )[lz -> rawsize ] = 0 ;
266
+ pglz_decompress (lz , VARDATA (result ));
262
267
263
268
return result ;
264
269
}
0 commit comments