Skip to content

Commit e986e30

Browse files
committed
Merge branch 'compression' into devel
* Fixed bug in determining file size for Unix-like systems. * Several optimizations of standard compression algorithm.
2 parents a47fa20 + 3175025 commit e986e30

File tree

16 files changed

+48229
-174
lines changed

16 files changed

+48229
-174
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*******************************************************************************
44

55
=== 1.0.29 ===
6+
* Fixed bug in determining file size for Unix-like systems.
7+
* Several optimizations of standard compression algorithm.
68
* Fixed bug in associativity of add, sub, mul, div and bit-and expressions.
79
* Added MacOS CI builds.
810

include/lsp-plug.in/resource/Compressor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace lsp
5050
size_t nSegment; // Start of data segment
5151
size_t nOffset; // Current offset in segment
5252
cbuffer_t sBuffer; // Buffer for caching
53+
// FILE *hFD;
5354

5455
protected:
5556
status_t alloc_entry(raw_resource_t **r, io::Path *path, resource_type_t type);

include/lsp-plug.in/resource/buffer.h

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
3-
* (C) 2021 Vladimir Sadovnikov <[email protected]>
2+
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2025 Vladimir Sadovnikov <[email protected]>
44
*
55
* This file is part of lsp-runtime-lib
66
* Created on: 13 мар. 2021 г.
@@ -54,9 +54,10 @@ namespace lsp
5454
public:
5555
uint8_t *data; // Buffer data (2 x capacity)
5656
uint32_t *index; // Index
57-
ssize_t head; // Head of the buffer
58-
ssize_t tail; // Buffer tail
59-
ssize_t cap; // Buffer capacity
57+
uint32_t *root; // Root index
58+
uint32_t head; // Head of the buffer
59+
uint32_t length; // Buffer length
60+
uint32_t cap; // Buffer capacity
6061

6162
public:
6263
explicit cbuffer_t();
@@ -66,11 +67,45 @@ namespace lsp
6667
void destroy();
6768

6869
public:
69-
void append(const void *src, ssize_t count);
70+
/**
71+
* Append buffer to compression buffer
72+
* @param src buffer to append
73+
* @param count the length of the buffer to append
74+
*/
75+
void append(const void *src, size_t count);
76+
77+
/**
78+
* Append single byte to compression buffer
79+
* @param v byte to append
80+
*/
7081
void append(uint8_t v);
71-
size_t lookup(ssize_t *out, const void *src, size_t avail);
82+
83+
/**
84+
* Lookup for byte sequence inside of the buffer
85+
* @param out relative offset of the sub-sequence in the buffer to the last byte stored in the buffer
86+
* @param src byte sequence to search inside of the buffer
87+
* @param avail number of bytes available in the sequence
88+
* @return the length of sub-sequence found in the buffer
89+
*/
90+
size_t lookup(size_t *out, const void *src, size_t avail);
91+
92+
/**
93+
* Get byte relative to the last written byte
94+
* @param offset offset relative to the last written byte
95+
* @return byte
96+
*/
97+
uint8_t byte_at(size_t offset);
98+
99+
/**
100+
* Cleanup state of the buffer
101+
*/
72102
void clear();
73-
inline size_t size() const { return tail - head; }
103+
104+
/**
105+
* Get size of data currently stored in the buffer
106+
* @return size of data currently stored in the buffer
107+
*/
108+
inline size_t size() const { return lsp_min(length, cap); }
74109

75110
} cbuffer_t;
76111

@@ -81,9 +116,9 @@ namespace lsp
81116
{
82117
public:
83118
uint8_t *data; // Buffer data (2 x capacity)
84-
ssize_t head; // Head of the buffer
85-
ssize_t tail; // Buffer tail
86-
ssize_t cap; // Buffer capacity
119+
uint32_t length; // Actual size of buffer
120+
uint32_t head; // Head of the buffer
121+
uint32_t cap; // Buffer capacity
87122

88123
public:
89124
explicit dbuffer_t();
@@ -93,14 +128,43 @@ namespace lsp
93128
void destroy();
94129

95130
public:
131+
/**
132+
* Extract data from buffer
133+
* @param dst destination pointer to store result
134+
* @param offset relative offset of the subsequence in the buffer to the last byte store in the buffer
135+
* @param count number of bytes to extract
136+
* @return status of operation (error on buffer underflow)
137+
*/
138+
status_t extract(void *dst, size_t offset, size_t count);
139+
140+
/**
141+
* Append multiple bytes to the buffer
142+
* @param src data to append to the buffer
143+
* @param count number of bytes to append
144+
*/
96145
void append(const void *src, ssize_t count);
146+
147+
/**
148+
* Append single byte to the buffer
149+
* @param v byt to append
150+
*/
97151
void append(uint8_t v);
152+
153+
/**
154+
* Clear buffer state
155+
*/
98156
void clear();
99-
inline size_t size() const { return tail - head; }
157+
158+
/**
159+
* Get size of data currently stored in the buffer
160+
* @return size of data currently stored in the buffer
161+
*/
162+
inline size_t size() const { return length; }
100163

101164
} duffer_t;
102-
}
103-
}
165+
166+
} /* namespace resource */
167+
} /* namespace lsp */
104168

105169

106170

0 commit comments

Comments
 (0)