#1054 Initialise data mask with expected number of elements

Merged Lionel Henry lionel-
Coverage Reach
src/lib/parse.c src/lib/vec.c src/lib/squash.c src/lib/env.c src/lib/cnd.c src/lib/replace-na.c src/lib/sym-unescape.c src/lib/vec-chr.c src/lib/eval.c src/lib/attrs.c src/lib/lang.c src/lib/formula.c src/lib/node.c src/lib/env-binding.c src/lib/rlang.c src/lib/sym.c src/lib/stack.c src/lib/vec.h src/lib/vec-lgl.c src/lib/vec-chr.h src/lib/sexp.h src/lib/node.h src/lib/c-utils.h src/lib/env.h src/lib/attrs.h src/lib/export.c src/lib/fn.h src/lib/weakref.c src/lib/session.c src/lib/sexp.c src/lib/vec-lgl.h src/lib/debug.c src/lib/vec-list.h src/lib/vec-list.c src/lib/export.h src/lib/fn.c src/lib/parse.h src/lib/sym.h src/lib/state.h src/lib/cnd.h src/lib/eval.h src/internal/dots.c src/internal/eval-tidy.c src/internal/expr-interp.c src/internal/env-binding.c src/internal/expr-interp-rotate.c src/internal/arg.c src/internal/attr.c src/internal/quo.c src/internal/vec-raw.c src/internal/call.c src/internal/internal.c src/internal/eval.c src/internal/utils.c src/internal/fn.c src/internal/expr-interp.h src/internal/internal.h src/internal/expr-interp-rotate.h src/internal/env.c src/internal/quo.h src/internal/utils.h src/export/exported.c src/export/exported-tests.c src/export/init.c src/capture.c src/version.c R/lifecycle-retired.R R/trace.R R/deparse.R R/quo.R R/call.R R/fn.R R/env.R R/dots.R R/utils.R R/cnd-abort.R R/env-binding.R R/nse-defuse.R R/cnd-error.R R/env-special.R R/cnd-signal.R R/cnd-entrace.R R/types.R R/expr.R R/formula.R R/eval-tidy.R R/arg.R R/utils-cli-tree.R R/node.R R/s3.R R/cnd-handlers.R R/cnd-message.R R/attr.R R/eval.R R/parse.R R/state.R R/stack.R R/nse-force.R R/vec-new.R R/utils-encoding.R R/vec.R R/rlang.R R/sym.R R/vec-squash.R R/operators.R R/cnd.R R/cnd-restarts.R R/vec-na.R R/raw.R R/utils-conditions.R R/weakref.R R/sexp.R

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 3 files from the diff.
Newly tracked file
src/lib/c-utils.h changed.
Other files ignored by Codecov
NEWS.md has changed.

@@ -1,6 +1,7 @@
Loading
1 1
#ifndef RLANG_C_UTILS_H
2 2
#define RLANG_C_UTILS_H
3 3
4 +
#include <float.h>
4 5
#include "cnd.h"
5 6
6 7
@@ -69,9 +70,39 @@
Loading
69 70
r_ssize r_ssize_min(r_ssize x, r_ssize y) {
70 71
  return (y < x) ? y : x;
71 72
}
73 +
72 74
static inline
73 75
r_ssize r_ssize_max(r_ssize x, r_ssize y) {
74 76
  return (y < x) ? x : y;
75 77
}
76 78
79 +
static inline
80 +
double r_ssize_as_double(r_ssize x) {
81 +
  if (x > DBL_MAX || x < -DBL_MAX) {
82 +
    r_stop_internal("r_ssize_as_double", "Result can't be represented as `double`.");
83 +
  }
84 +
85 +
  return (double) x;
86 +
}
87 +
88 +
static inline
89 +
r_ssize r_double_as_ssize(double x) {
90 +
  if (x > R_SSIZE_MAX || x < R_SSIZE_MIN) {
91 +
    r_stop_internal("r_ssize_as_double", "Result can't be represented as `r_ssize`.");
92 +
  }
93 +
94 +
  return (r_ssize) x;
95 +
}
96 +
97 +
static inline
98 +
double r_double_mult(double x, double y) {
99 +
  double out = x * y;
100 +
101 +
  if (!isfinite(out)) {
102 +
    r_stop_internal("r_double_mult", "Can't multiply double values.");
103 +
  }
104 +
105 +
  return out;
106 +
}
107 +
77 108
#endif

@@ -160,14 +160,14 @@
Loading
160 160
  sexp* data_mask;
161 161
162 162
  if (bottom == r_null) {
163 -
    bottom = KEEP(r_new_environment(r_empty_env, 0));
163 +
    bottom = KEEP(r_new_environment(r_empty_env, 100));
164 164
    data_mask = bottom;
165 165
  } else {
166 166
    check_data_mask_input(bottom, "bottom");
167 167
    // Create a child because we don't know what might be in `bottom`
168 168
    // and we need to clear its contents without deleting any object
169 169
    // created in the data mask environment
170 -
    data_mask = KEEP(r_new_environment(bottom, 0));
170 +
    data_mask = KEEP(r_new_environment(bottom, 100));
171 171
  }
172 172
173 173
  if (top == r_null) {
@@ -271,6 +271,7 @@
Loading
271 271
}
272 272
273 273
static sexp* data_pronoun_sym = NULL;
274 +
static r_ssize mask_length(r_ssize n);
274 275
275 276
sexp* rlang_as_data_mask(sexp* data) {
276 277
  if (mask_info(data).type == RLANG_MASK_DATA) {
@@ -304,7 +305,9 @@
Loading
304 305
    check_unique_names(data);
305 306
306 307
    sexp* names = r_names(data);
307 -
    bottom = KEEP_N(r_new_environment(r_empty_env, 0), n_protect);
308 +
309 +
    r_ssize n_mask = mask_length(r_length(data));
310 +
    bottom = KEEP_N(r_new_environment(r_empty_env, n_mask), n_protect);
308 311
309 312
    if (names != r_null) {
310 313
      r_ssize n = r_length(data);
@@ -335,6 +338,12 @@
Loading
335 338
  return data_mask;
336 339
}
337 340
341 +
static
342 +
r_ssize mask_length(r_ssize n) {
343 +
  r_ssize n_grown = r_double_as_ssize(r_double_mult(r_ssize_as_double(n), 1.05));
344 +
  return r_ssize_max(n_grown, r_ssize_add(n, 20));
345 +
}
346 +
338 347
// For compatibility of the exported C callable
339 348
// TODO: warn
340 349
sexp* rlang_new_data_mask_compat(sexp* bottom, sexp* top, sexp* parent) {

Learn more Showing 1 files with coverage changes found.

New file src/lib/c-utils.h
New
Loading file...
Files Coverage
R 83.67%
src -0.04% 88.64%
Project Totals (112 files) 86.22%
Loading