Skip to content

Commit

Permalink
Make common non-member functions inline, remove unreachable line from…
Browse files Browse the repository at this point in the history
… get_line_buffer
  • Loading branch information
red0124 committed Mar 12, 2024
1 parent 1b9a01f commit 32f3485
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
compile_commands.json
.clang-format
.ccls-cache/*
.cache/
experiment/
build/
hbuild/
Expand Down
14 changes: 5 additions & 9 deletions include/ss/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
inline std::tuple<ssize_t, bool> 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) {
Expand Down
1 change: 0 additions & 1 deletion include/ss/splitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <string>
#include <vector>

Expand Down
15 changes: 5 additions & 10 deletions ssp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cstring>
#include <exception>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<ssize_t, bool> get_line(char*& buffer, size_t& buffer_size,
inline std::tuple<ssize_t, bool> 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) {
Expand Down

0 comments on commit 32f3485

Please sign in to comment.