Make common non-member functions inline, remove unreachable line from get_line_buffer

This commit is contained in:
ado 2024-03-12 02:53:19 +01:00
parent 1b9a01f787
commit 32f3485233
4 changed files with 11 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
compile_commands.json compile_commands.json
.clang-format .clang-format
.ccls-cache/* .ccls-cache/*
.cache/
experiment/ experiment/
build/ build/
hbuild/ hbuild/

View File

@ -45,7 +45,7 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
using ssize_t = intptr_t; 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]; char buff[get_line_initial_buffer_size];
if (lineptr == nullptr || n < sizeof(buff)) { if (lineptr == nullptr || n < sizeof(buff)) {
@ -81,7 +81,7 @@ ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
#endif #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, const char* const csv_data_buffer, size_t csv_data_size,
size_t& curr_char) { size_t& curr_char) {
if (curr_char >= csv_data_size) { 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'; lineptr[line_used] = '\0';
return line_used; return line_used;
} }
return -1; inline std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
}
std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
FILE* file, FILE* file,
const char* const csv_data_buffer, const char* const csv_data_buffer,
size_t csv_data_size, size_t& curr_char) { size_t csv_data_size, size_t& curr_char) {

View File

@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>

11
ssp.hpp
View File

@ -8,7 +8,6 @@
#include <cstring> #include <cstring>
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -657,7 +656,7 @@ inline ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
using ssize_t = intptr_t; 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]; char buff[get_line_initial_buffer_size];
if (lineptr == nullptr || n < sizeof(buff)) { if (lineptr == nullptr || n < sizeof(buff)) {
@ -693,7 +692,7 @@ ssize_t get_line_file(char*& lineptr, size_t& n, FILE* file) {
#endif #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, const char* const csv_data_buffer, size_t csv_data_size,
size_t& curr_char) { size_t& curr_char) {
if (curr_char >= csv_data_size) { 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'; lineptr[line_used] = '\0';
return line_used; return line_used;
} }
return -1; inline std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
}
std::tuple<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
FILE* file, FILE* file,
const char* const csv_data_buffer, const char* const csv_data_buffer,
size_t csv_data_size, size_t& curr_char) { size_t csv_data_size, size_t& curr_char) {