rust: Reworked npnr_context_get_pips_leak()
using std::accumulate() and fixed an accidental copy problem
This commit is contained in:
parent
7d0c4eaf1b
commit
cfeb588d32
14
rust/rust.cc
14
rust/rust.cc
@ -102,15 +102,15 @@ extern "C" {
|
|||||||
Loc npnr_context_get_pip_location(const Context *ctx, uint64_t pip) { return ctx->getPipLocation(unwrap_pip(pip)); }
|
Loc npnr_context_get_pip_location(const Context *ctx, uint64_t pip) { return ctx->getPipLocation(unwrap_pip(pip)); }
|
||||||
bool npnr_context_check_pip_avail_for_net(const Context *ctx, uint64_t pip, NetInfo *net) { return ctx->checkPipAvailForNet(unwrap_pip(pip), net); }
|
bool npnr_context_check_pip_avail_for_net(const Context *ctx, uint64_t pip, NetInfo *net) { return ctx->checkPipAvailForNet(unwrap_pip(pip), net); }
|
||||||
|
|
||||||
uint64_t npnr_context_get_pips_leak(const Context *ctx, uint64_t **pips) {
|
uint64_t npnr_context_get_pips_leak(const Context *const ctx, uint64_t **const pips) {
|
||||||
auto size = size_t{};
|
const auto ctx_pips{ctx->getPips()};
|
||||||
for (auto _pip : ctx->getPips()) {
|
const auto size{
|
||||||
NPNR_UNUSED(_pip);
|
std::accumulate(ctx_pips.begin(), ctx_pips.end(), /*initial value*/ size_t{},
|
||||||
size++;
|
[](size_t value, const auto &/*pip*/) { return value + 1U; }
|
||||||
}
|
)};
|
||||||
*pips = new uint64_t[size];
|
*pips = new uint64_t[size];
|
||||||
auto idx = 0;
|
auto idx = 0;
|
||||||
for (auto pip : ctx->getPips()) {
|
for (const auto &pip : ctx_pips) {
|
||||||
(*pips)[idx] = wrap(pip);
|
(*pips)[idx] = wrap(pip);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user