diff --git a/include/ss/common.hpp b/include/ss/common.hpp index 430f8ee..70c8241 100644 --- a/include/ss/common.hpp +++ b/include/ss/common.hpp @@ -12,6 +12,7 @@ using string_range = std::pair; using split_data = std::vector; constexpr inline auto default_delimiter = ","; +constexpr static auto get_line_initial_buffer_size = 128; template 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) { - *lineptr = static_cast(malloc(128)); + *lineptr = static_cast(malloc(get_line_initial_buffer_size)); if (*lineptr == nullptr) { return -1; } @@ -57,8 +58,8 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) { while (c != EOF) { if (pos + 1 >= *n) { size_t new_size = *n + (*n >> 2); - if (new_size < 128) { - new_size = 128; + if (new_size < get_line_initial_buffer_size) { + new_size = get_line_initial_buffer_size; } char* new_ptr = static_cast( realloc(static_cast(*lineptr), new_size)); diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 51031b5..a7319ee 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -752,7 +752,8 @@ private: c = buffer[curr_char++]; if (*lineptr == nullptr) { - *lineptr = static_cast(malloc(128)); + *lineptr = + static_cast(malloc(get_line_initial_buffer_size)); if (*lineptr == nullptr) { return -1; } @@ -763,8 +764,8 @@ private: while (curr_char <= csv_data_size) { if (pos + 1 >= *n) { size_t new_size = *n + (*n >> 2); - if (new_size < 128) { - new_size = 128; + if (new_size < get_line_initial_buffer_size) { + new_size = get_line_initial_buffer_size; } char* new_ptr = static_cast( realloc(static_cast(*lineptr), new_size)); diff --git a/ssp.hpp b/ssp.hpp index 807e55e..9b555ec 100644 --- a/ssp.hpp +++ b/ssp.hpp @@ -625,6 +625,7 @@ using string_range = std::pair; using split_data = std::vector; constexpr inline auto default_delimiter = ","; +constexpr static auto get_line_initial_buffer_size = 128; template 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) { - *lineptr = static_cast(malloc(128)); + *lineptr = static_cast(malloc(get_line_initial_buffer_size)); if (*lineptr == nullptr) { return -1; } @@ -670,8 +671,8 @@ inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) { while (c != EOF) { if (pos + 1 >= *n) { size_t new_size = *n + (*n >> 2); - if (new_size < 128) { - new_size = 128; + if (new_size < get_line_initial_buffer_size) { + new_size = get_line_initial_buffer_size; } char* new_ptr = static_cast( realloc(static_cast(*lineptr), new_size)); @@ -2878,7 +2879,8 @@ private: c = buffer[curr_char++]; if (*lineptr == nullptr) { - *lineptr = static_cast(malloc(128)); + *lineptr = + static_cast(malloc(get_line_initial_buffer_size)); if (*lineptr == nullptr) { return -1; } @@ -2889,8 +2891,8 @@ private: while (curr_char <= csv_data_size) { if (pos + 1 >= *n) { size_t new_size = *n + (*n >> 2); - if (new_size < 128) { - new_size = 128; + if (new_size < get_line_initial_buffer_size) { + new_size = get_line_initial_buffer_size; } char* new_ptr = static_cast( realloc(static_cast(*lineptr), new_size));