Entt: use null for recycling when available == 0

Created on 16 Aug 2019  路  1Comment  路  Source: skypjack/entt

@skypjack suggested that I open an issue for a question on this line:

https://github.com/skypjack/entt/blob/688e6ad79fcc443d395351f15e447005b668d8dc/src/entt/entity/registry.hpp#L235

When available is 0, the index portion of the next entity is currently set to the old index + 1.

It doesn't really matter what this value is set to, as long as it's not equal to the index, since the node won't be visited anyway in this case and the meaning of the value here is purely used to manually check if a given entity is dead or alive.

Since it doesn't matter, it would be a little nicer and faster if null were used instead since it's a constant.

enhancement

Most helpful comment

I used null to initialize next and removed the check on available. Therefore this:

 const auto node = (available ? to_integer(next) : ((entt + 1) & traits_type::entity_mask)) | version;

Now looks like this:

 const auto node = to_integer(next) | version;

Deleting entities should be even slightly faster as a consequence. :+1:
Thank you for pointing this out.

>All comments

I used null to initialize next and removed the check on available. Therefore this:

 const auto node = (available ? to_integer(next) : ((entt + 1) & traits_type::entity_mask)) | version;

Now looks like this:

 const auto node = to_integer(next) | version;

Deleting entities should be even slightly faster as a consequence. :+1:
Thank you for pointing this out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bjadamson picture bjadamson  路  4Comments

skypjack picture skypjack  路  7Comments

netpoetica picture netpoetica  路  6Comments

blockspacer picture blockspacer  路  3Comments

skypjack picture skypjack  路  4Comments