Skip to content

Commit

Permalink
factor out .size() checks in GetDataType() (#4541)
Browse files Browse the repository at this point in the history
* factor out .size() checks in GetDataType()

* Update src/io/parser.cpp

Co-authored-by: Nikita Titov <nekit94-08@mail.ru>

Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
  • Loading branch information
jameslamb and StrikerRUS authored Aug 22, 2021
1 parent 4e18c60 commit 4db10d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/io/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,16 @@ DataType GetDataType(const char* filename, bool header,
int tab_cnt = 0;
int colon_cnt = 0;
GetStatistic(lines[0].c_str(), &comma_cnt, &tab_cnt, &colon_cnt);
if (lines.size() == 1) {
size_t num_lines = lines.size();
if (num_lines == 1) {
if (colon_cnt > 0) {
type = DataType::LIBSVM;
} else if (tab_cnt > 0) {
type = DataType::TSV;
} else if (comma_cnt > 0) {
type = DataType::CSV;
}
} else if (lines.size() > 1) {
} else {
int comma_cnt2 = 0;
int tab_cnt2 = 0;
int colon_cnt2 = 0;
Expand All @@ -206,7 +207,7 @@ DataType GetDataType(const char* filename, bool header,
}
if (type == DataType::TSV || type == DataType::CSV) {
// valid the type
for (size_t i = 2; i < lines.size(); ++i) {
for (size_t i = 2; i < num_lines; ++i) {
GetStatistic(lines[i].c_str(), &comma_cnt2, &tab_cnt2, &colon_cnt2);
if (type == DataType::TSV && tab_cnt2 != tab_cnt) {
type = DataType::INVALID;
Expand Down

0 comments on commit 4db10d8

Please sign in to comment.