mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
[skip ci] Remove some magic numbers
This commit is contained in:
parent
aaa22046a5
commit
d422667477
@ -12,6 +12,7 @@ using string_range = std::pair<const char*, const char*>;
|
|||||||
using split_data = std::vector<string_range>;
|
using split_data = std::vector<string_range>;
|
||||||
|
|
||||||
constexpr inline auto default_delimiter = ",";
|
constexpr inline auto default_delimiter = ",";
|
||||||
|
constexpr static auto get_line_initial_buffer_size = 128;
|
||||||
|
|
||||||
template <bool StringError>
|
template <bool StringError>
|
||||||
inline void assert_string_error_defined() {
|
inline void assert_string_error_defined() {
|
||||||
@ -46,7 +47,7 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
*lineptr = static_cast<char*>(malloc(128));
|
*lineptr = static_cast<char*>(malloc(get_line_initial_buffer_size));
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -57,8 +58,8 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
|||||||
while (c != EOF) {
|
while (c != EOF) {
|
||||||
if (pos + 1 >= *n) {
|
if (pos + 1 >= *n) {
|
||||||
size_t new_size = *n + (*n >> 2);
|
size_t new_size = *n + (*n >> 2);
|
||||||
if (new_size < 128) {
|
if (new_size < get_line_initial_buffer_size) {
|
||||||
new_size = 128;
|
new_size = get_line_initial_buffer_size;
|
||||||
}
|
}
|
||||||
char* new_ptr = static_cast<char*>(
|
char* new_ptr = static_cast<char*>(
|
||||||
realloc(static_cast<void*>(*lineptr), new_size));
|
realloc(static_cast<void*>(*lineptr), new_size));
|
||||||
|
@ -752,7 +752,8 @@ private:
|
|||||||
c = buffer[curr_char++];
|
c = buffer[curr_char++];
|
||||||
|
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
*lineptr = static_cast<char*>(malloc(128));
|
*lineptr =
|
||||||
|
static_cast<char*>(malloc(get_line_initial_buffer_size));
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -763,8 +764,8 @@ private:
|
|||||||
while (curr_char <= csv_data_size) {
|
while (curr_char <= csv_data_size) {
|
||||||
if (pos + 1 >= *n) {
|
if (pos + 1 >= *n) {
|
||||||
size_t new_size = *n + (*n >> 2);
|
size_t new_size = *n + (*n >> 2);
|
||||||
if (new_size < 128) {
|
if (new_size < get_line_initial_buffer_size) {
|
||||||
new_size = 128;
|
new_size = get_line_initial_buffer_size;
|
||||||
}
|
}
|
||||||
char* new_ptr = static_cast<char*>(
|
char* new_ptr = static_cast<char*>(
|
||||||
realloc(static_cast<void*>(*lineptr), new_size));
|
realloc(static_cast<void*>(*lineptr), new_size));
|
||||||
|
14
ssp.hpp
14
ssp.hpp
@ -625,6 +625,7 @@ using string_range = std::pair<const char*, const char*>;
|
|||||||
using split_data = std::vector<string_range>;
|
using split_data = std::vector<string_range>;
|
||||||
|
|
||||||
constexpr inline auto default_delimiter = ",";
|
constexpr inline auto default_delimiter = ",";
|
||||||
|
constexpr static auto get_line_initial_buffer_size = 128;
|
||||||
|
|
||||||
template <bool StringError>
|
template <bool StringError>
|
||||||
inline void assert_string_error_defined() {
|
inline void assert_string_error_defined() {
|
||||||
@ -659,7 +660,7 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
*lineptr = static_cast<char*>(malloc(128));
|
*lineptr = static_cast<char*>(malloc(get_line_initial_buffer_size));
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -670,8 +671,8 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
|||||||
while (c != EOF) {
|
while (c != EOF) {
|
||||||
if (pos + 1 >= *n) {
|
if (pos + 1 >= *n) {
|
||||||
size_t new_size = *n + (*n >> 2);
|
size_t new_size = *n + (*n >> 2);
|
||||||
if (new_size < 128) {
|
if (new_size < get_line_initial_buffer_size) {
|
||||||
new_size = 128;
|
new_size = get_line_initial_buffer_size;
|
||||||
}
|
}
|
||||||
char* new_ptr = static_cast<char*>(
|
char* new_ptr = static_cast<char*>(
|
||||||
realloc(static_cast<void*>(*lineptr), new_size));
|
realloc(static_cast<void*>(*lineptr), new_size));
|
||||||
@ -2878,7 +2879,8 @@ private:
|
|||||||
c = buffer[curr_char++];
|
c = buffer[curr_char++];
|
||||||
|
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
*lineptr = static_cast<char*>(malloc(128));
|
*lineptr =
|
||||||
|
static_cast<char*>(malloc(get_line_initial_buffer_size));
|
||||||
if (*lineptr == nullptr) {
|
if (*lineptr == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2889,8 +2891,8 @@ private:
|
|||||||
while (curr_char <= csv_data_size) {
|
while (curr_char <= csv_data_size) {
|
||||||
if (pos + 1 >= *n) {
|
if (pos + 1 >= *n) {
|
||||||
size_t new_size = *n + (*n >> 2);
|
size_t new_size = *n + (*n >> 2);
|
||||||
if (new_size < 128) {
|
if (new_size < get_line_initial_buffer_size) {
|
||||||
new_size = 128;
|
new_size = get_line_initial_buffer_size;
|
||||||
}
|
}
|
||||||
char* new_ptr = static_cast<char*>(
|
char* new_ptr = static_cast<char*>(
|
||||||
realloc(static_cast<void*>(*lineptr), new_size));
|
realloc(static_cast<void*>(*lineptr), new_size));
|
||||||
|
Loading…
Reference in New Issue
Block a user