Skip to content

Commit 0cafb49

Browse files
committed
Use a compile time constant for def_mem_level and def_buf_size
1 parent 0307ba8 commit 0cafb49

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/isal/isal_zlib.pyx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ Z_BEST_SPEED = ISAL_BEST_SPEED
4646
Z_BEST_COMPRESSION = ISAL_BEST_COMPRESSION
4747
Z_DEFAULT_COMPRESSION = ISAL_DEFAULT_COMPRESSION
4848

49-
DEF_BUF_SIZE = zlib.DEF_BUF_SIZE
50-
DEF_MEM_LEVEL = zlib.DEF_MEM_LEVEL
51-
cdef int DEF_MEM_LEVEL_I = zlib.DEF_MEM_LEVEL # Can not be manipulated by user.
49+
# Compile time constants with _I (for integer suffix) as names without
50+
# suffix should be exposed to the user.
51+
DEF DEF_BUF_SIZE_I = 16 * 1024
52+
DEF DEF_MEM_LEVEL_I = 8
53+
54+
# Expose compile-time constants. Same names as zlib.
55+
DEF_BUF_SIZE = DEF_BUF_SIZE_I
56+
DEF_MEM_LEVEL = DEF_MEM_LEVEL_I
5257
MAX_WBITS = ISAL_DEF_MAX_HIST_BITS
5358
ISAL_DEFAULT_HIST_BITS=0
5459

@@ -204,7 +209,7 @@ def compress(data,
204209
&stream.gzip_flag)
205210

206211
# Initialise output buffer
207-
cdef Py_ssize_t bufsize = DEF_BUF_SIZE
212+
cdef Py_ssize_t bufsize = DEF_BUF_SIZE_I
208213
cdef unsigned char * obuf = NULL
209214

210215
# initialise input
@@ -422,7 +427,7 @@ cdef class Compress:
422427
"""
423428
# Initialise output buffer
424429
cdef unsigned char * obuf = NULL
425-
cdef Py_ssize_t obuflen = DEF_BUF_SIZE
430+
cdef Py_ssize_t obuflen = DEF_BUF_SIZE_I
426431

427432
# initialise input
428433
cdef Py_buffer buffer_data
@@ -484,7 +489,7 @@ cdef class Compress:
484489
else:
485490
raise IsalError("Unsupported flush mode")
486491

487-
cdef Py_ssize_t length = DEF_BUF_SIZE
492+
cdef Py_ssize_t length = DEF_BUF_SIZE_I
488493
cdef unsigned char * obuf = NULL
489494

490495
try:
@@ -613,7 +618,7 @@ cdef class Decompress:
613618

614619
# Initialise output buffer
615620
cdef unsigned char *obuf = NULL
616-
cdef Py_ssize_t obuflen = DEF_BUF_SIZE
621+
cdef Py_ssize_t obuflen = DEF_BUF_SIZE_I
617622
if obuflen > hard_limit:
618623
obuflen = hard_limit
619624

0 commit comments

Comments
 (0)