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

New World::extend_out function #255

Merged
merged 3 commits into from
Apr 26, 2021

Conversation

ImmemorConsultrixContrarie
Copy link
Contributor

Description

Adds a new method for World struct.

The function extends a user-provided collection directly instead of writing to internal buffer and then giving a reference to the contents of the buffer.

Because Vec::extend_from_slice simply redirects to Vec::extend, World::extend was changed to use World::extend_out; there should be no performance difference.

Also World::push uses World::extend_out to avoid allocation in World::extend.

Motivation and Context

Mostly to allow users skip an intermediate buffer to do insertions a little bit faster.

Fixes #218.
Well, not so much of an issue fix, because the fix for the issue is really simple:

// instead of this:
let entities = world.extend(v);
// write this:
let entities = world.extend(v).to_owned();

but anyway, the code could also be fixed with this new function without a cost of additional allocations.

How Has This Been Tested?

cargo test

Because extend and push use the new function, this should be enough, as every test for push and extend is also a test for extend_out.

Checklist:

  • Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.
  • My code follows the code style of this project.
  • If my change required a change to the documentation I have updated the documentation accordingly.
  • I have updated the content of the book if this PR would make the book outdated.
  • I have added tests to cover my changes.
  • My code is used in an example.

Extends a user-provided collection directly instead of
writing to internal buffer and then giving a referenceto the contents of the buffer.
@TomGillen TomGillen added the type: feature New feature or request label Apr 26, 2021
@TomGillen
Copy link
Collaborator

bors r+

@bors bors bot merged commit bb48bd7 into amethyst:master Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is that possible to use world.entry() on entity arrays created by world.extend()?
2 participants