Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Replace shared_ptr creation hack before AppendScalarImpl instantiation #33872

Closed
felipecrv opened this issue Jan 26, 2023 · 0 comments · Fixed by #33866
Closed

[C++] Replace shared_ptr creation hack before AppendScalarImpl instantiation #33872

felipecrv opened this issue Jan 26, 2023 · 0 comments · Fixed by #33866

Comments

@felipecrv
Copy link
Contributor

felipecrv commented Jan 26, 2023

Describe the enhancement requested

AppendScalarImpl was created for appending scalars based on a contiguous array of std::shared_ptr<Scalar>, so when a single Scalar reference is passed, a dummy shared_ptr is created before the instantiation of AppendScalarImpl.

  std::shared_ptr<Scalar> shared{const_cast<Scalar*>(&scalar), [](Scalar*) {}};
  return AppendScalarImpl{&shared, &shared + 1, n_repeats, this}.Convert();

This seems non-idiomatic [1] and likely inefficient as a control block needs to be heap-allocated for the shared_ptr. An alternative way (that simplifies AppendScalarImpl as well) is a custom iterator class the wraps the source iterator with an extra dereference operation.

[1] Pointers to shared_ptr as class members set a bad-style precedent

Component(s)

C++

@lidavidm lidavidm changed the title Replace shared_ptr creation hack before AppendScalarImpl instantiation [C++] Replace shared_ptr creation hack before AppendScalarImpl instantiation Jan 26, 2023
@lidavidm lidavidm added this to the 12.0.0 milestone Jan 26, 2023
lidavidm pushed a commit that referenced this issue Jan 26, 2023
…33866)

`AppendScalarImpl` was created for appending scalars based on a contiguous array of `std::shared_ptr<Scalar>`, so when a single `Scalar` reference is passed, a dummy `shared_ptr` is created before the instantiation of `AppendScalarImpl`.

```cpp
  std::shared_ptr<Scalar> shared{const_cast<Scalar*>(&scalar), [](Scalar*) {}};
  return AppendScalarImpl{&shared, &shared + 1, n_repeats, this}.Convert();
```

This seems non-idiomatic [1] and likely inefficient as a control block needs to be heap-allocated for the `shared_ptr`. An alternative way (that simplifies `AppendScalarImpl` as well) is a custom iterator class the wraps the source iterator with an extra dereference operation.

[1] Pointers to `shared_ptr` as class members set a bad-style precedent

### Component(s)

C++

* Closes: #33872

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
sjperkins pushed a commit to sjperkins/arrow that referenced this issue Feb 10, 2023
…calar (apache#33866)

`AppendScalarImpl` was created for appending scalars based on a contiguous array of `std::shared_ptr<Scalar>`, so when a single `Scalar` reference is passed, a dummy `shared_ptr` is created before the instantiation of `AppendScalarImpl`.

```cpp
  std::shared_ptr<Scalar> shared{const_cast<Scalar*>(&scalar), [](Scalar*) {}};
  return AppendScalarImpl{&shared, &shared + 1, n_repeats, this}.Convert();
```

This seems non-idiomatic [1] and likely inefficient as a control block needs to be heap-allocated for the `shared_ptr`. An alternative way (that simplifies `AppendScalarImpl` as well) is a custom iterator class the wraps the source iterator with an extra dereference operation.

[1] Pointers to `shared_ptr` as class members set a bad-style precedent

### Component(s)

C++

* Closes: apache#33872

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
gringasalpastor pushed a commit to gringasalpastor/arrow that referenced this issue Feb 17, 2023
…calar (apache#33866)

`AppendScalarImpl` was created for appending scalars based on a contiguous array of `std::shared_ptr<Scalar>`, so when a single `Scalar` reference is passed, a dummy `shared_ptr` is created before the instantiation of `AppendScalarImpl`.

```cpp
  std::shared_ptr<Scalar> shared{const_cast<Scalar*>(&scalar), [](Scalar*) {}};
  return AppendScalarImpl{&shared, &shared + 1, n_repeats, this}.Convert();
```

This seems non-idiomatic [1] and likely inefficient as a control block needs to be heap-allocated for the `shared_ptr`. An alternative way (that simplifies `AppendScalarImpl` as well) is a custom iterator class the wraps the source iterator with an extra dereference operation.

[1] Pointers to `shared_ptr` as class members set a bad-style precedent

### Component(s)

C++

* Closes: apache#33872

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants