MCPcopy Create free account
hub / github.com/apache/arrow / utf8_strings

Function utf8_strings

r/src/arrow_cpp11.h:133–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131} // namespace unsafe
132
133inline SEXP utf8_strings(SEXP x) {
134 return cpp11::unwind_protect([&] {
135 // ensure that x is not actually altrep first this also ensures that
136 // x is not altrep even after it is materialized
137 bool was_altrep = ALTREP(x);
138 if (was_altrep) {
139 x = PROTECT(Rf_duplicate(x));
140 }
141 R_xlen_t n = XLENGTH(x);
142
143 // if `x` is an altrep of some sort, this will
144 // materialize upfront. That's usually better because
145 // the loop touches all strings
146 const SEXP* p_x = STRING_PTR_RO(x);
147
148 for (R_xlen_t i = 0; i < n; i++, ++p_x) {
149 SEXP s = *p_x;
150 if (s != NA_STRING) {
151 SET_STRING_ELT(x, i, Rf_mkCharCE(Rf_translateCharUTF8(s), CE_UTF8));
152 }
153 }
154 if (was_altrep) {
155 UNPROTECT(1);
156 }
157 return x;
158 });
159}
160
161struct symbols {
162 static SEXP units;

Callers 1

ExtendMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected