Skip to content

Commit ce1b2d4

Browse files
authored
Merge pull request #9 from gergness/chat-gpt-rf-lengthgets
Resize vectors in C++ code with `rf_lengthgets()` instead of non-API functions SETLENGTH and SET_TRUELENGTH.
2 parents 4e62151 + db850e4 commit ce1b2d4

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

src/column.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "string_utils.h"
66
#include "iconv.h"
77

8+
89
#include <Rcpp.h>
910
using namespace Rcpp;
1011

@@ -101,47 +102,28 @@ void ColumnInteger::setValue(int i, const char* x_start, const char* x_end) {
101102
}
102103

103104
void ColumnCharacter::resize(int n) {
104-
if (n == n_)
105-
return;
106-
107-
if (n > 0 && n < n_) {
108-
SETLENGTH(values_, n);
109-
SET_TRUELENGTH(values_, n);
110-
} else {
111-
values_ = Rf_lengthgets(values_, n);
112-
}
105+
if (n == n_) return;
106+
values_ = Rf_lengthgets(values_, n);
113107
n_ = n;
114-
115108
}
116109

117-
void ColumnDouble::resize(int n) {
118-
if (n == n_)
119-
return;
120110

121-
if (n > 0 && n < n_) {
122-
SETLENGTH(values_, n);
123-
SET_TRUELENGTH(values_, n);
124-
} else {
125-
values_ = Rf_lengthgets(values_, n);
126-
}
111+
void ColumnDouble::resize(int n) {
112+
if (n == n_) return;
113+
values_ = Rf_lengthgets(values_, n);
127114
n_ = n;
128115
valuepointer = REAL(values_);
129116
}
130117

131-
void ColumnInteger::resize(int n) {
132-
if (n == n_)
133-
return;
134118

135-
if (n > 0 && n < n_) {
136-
SETLENGTH(values_, n);
137-
SET_TRUELENGTH(values_, n);
138-
} else {
139-
values_ = Rf_lengthgets(values_, n);
140-
}
119+
void ColumnInteger::resize(int n) {
120+
if (n == n_) return;
121+
values_ = Rf_lengthgets(values_, n);
141122
n_ = n;
142123
valuepointer = INTEGER(values_);
143124
}
144125

126+
145127
std::vector<ColumnPtr> createAllColumns(CharacterVector types, Rcpp::List var_opts, Iconv* pEncoder_) {
146128
int num_cols = static_cast<int>(types.size());
147129
std::vector<ColumnPtr> out;

0 commit comments

Comments
 (0)