From 32f34852338ead43d072dfc05594249d306d0215 Mon Sep 17 00:00:00 2001 From: ado Date: Tue, 12 Mar 2024 02:53:19 +0100 Subject: [PATCH] Make common non-member functions inline, remove unreachable line from get_line_buffer --- .gitignore | 1 + include/ss/common.hpp | 14 +++++--------- include/ss/splitter.hpp | 1 - ssp.hpp | 15 +++++---------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index eb880af..d562a42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ compile_commands.json .clang-format .ccls-cache/* +.cache/ experiment/ build/ hbuild/ diff --git a/include/ss/common.hpp b/include/ss/common.hpp index c70230e..3868d06 100644 --- a/include/ss/common.hpp +++ b/include/ss/common.hpp @@ -45,7 +45,7 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { using ssize_t = intptr_t; -ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { +inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { char buff[get_line_initial_buffer_size]; if (lineptr == nullptr || n < sizeof(buff)) { @@ -81,7 +81,7 @@ ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { #endif -ssize_t get_line_buffer(char*& lineptr, size_t& n, +inline ssize_t get_line_buffer(char*& lineptr, size_t& n, const char* const csv_data_buffer, size_t csv_data_size, size_t& curr_char) { if (curr_char >= csv_data_size) { @@ -114,15 +114,11 @@ ssize_t get_line_buffer(char*& lineptr, size_t& n, } } - if (line_used != 0) { - lineptr[line_used] = '\0'; - return line_used; - } - - return -1; + lineptr[line_used] = '\0'; + return line_used; } -std::tuple get_line(char*& buffer, size_t& buffer_size, +inline std::tuple get_line(char*& buffer, size_t& buffer_size, FILE* file, const char* const csv_data_buffer, size_t csv_data_size, size_t& curr_char) { diff --git a/include/ss/splitter.hpp b/include/ss/splitter.hpp index d974e83..a33cef6 100644 --- a/include/ss/splitter.hpp +++ b/include/ss/splitter.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include diff --git a/ssp.hpp b/ssp.hpp index 811a490..02466cb 100644 --- a/ssp.hpp +++ b/ssp.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -657,7 +656,7 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { using ssize_t = intptr_t; -ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { +inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { char buff[get_line_initial_buffer_size]; if (lineptr == nullptr || n < sizeof(buff)) { @@ -693,7 +692,7 @@ ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) { #endif -ssize_t get_line_buffer(char*& lineptr, size_t& n, +inline ssize_t get_line_buffer(char*& lineptr, size_t& n, const char* const csv_data_buffer, size_t csv_data_size, size_t& curr_char) { if (curr_char >= csv_data_size) { @@ -726,15 +725,11 @@ ssize_t get_line_buffer(char*& lineptr, size_t& n, } } - if (line_used != 0) { - lineptr[line_used] = '\0'; - return line_used; - } - - return -1; + lineptr[line_used] = '\0'; + return line_used; } -std::tuple get_line(char*& buffer, size_t& buffer_size, +inline std::tuple get_line(char*& buffer, size_t& buffer_size, FILE* file, const char* const csv_data_buffer, size_t csv_data_size, size_t& curr_char) {