Skip to content

Commit 1e28930

Browse files
committed
askrene: remove allocation checks
Rusty: "allocations don't fail" Signed-off-by: Lagrang3 <[email protected]>
1 parent f4ec865 commit 1e28930

File tree

2 files changed

+0
-31
lines changed

2 files changed

+0
-31
lines changed

plugins/askrene/algorithm.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ bool dijkstra_path(const tal_t *ctx, const struct graph *graph,
101101
bitmap *visited = tal_arrz(this_ctx, bitmap,
102102
BITMAP_NWORDS(max_num_nodes));
103103

104-
if (!visited)
105-
/* bad allocation */
106-
goto finish;
107-
108104
for (size_t i = 0; i < max_num_nodes; ++i)
109105
prev[i].idx = INVALID_INDEX;
110106

@@ -158,7 +154,6 @@ bool dijkstra_path(const tal_t *ctx, const struct graph *graph,
158154
for (size_t i = 0; i < max_num_nodes; i++)
159155
distance[i] = dijkstra_distance[i];
160156

161-
finish:
162157
tal_free(this_ctx);
163158
return target_found;
164159
}
@@ -357,10 +352,6 @@ static struct node dijkstra_nearest_sink(const tal_t *ctx,
357352
struct node target = {.idx = INVALID_INDEX};
358353
const tal_t *this_ctx = tal(ctx, tal_t);
359354

360-
if (!this_ctx)
361-
/* bad allocation */
362-
goto finish;
363-
364355
/* check preconditions */
365356
assert(graph);
366357
assert(node_balance);
@@ -405,7 +396,6 @@ static struct node dijkstra_nearest_sink(const tal_t *ctx,
405396
#ifdef ASKRENE_UNITTEST
406397
bitmap *visited =
407398
tal_arrz(this_ctx, bitmap, BITMAP_NWORDS(max_num_nodes));
408-
assert(visited);
409399
#endif
410400

411401
struct priorityqueue *q;
@@ -510,10 +500,6 @@ bool mcf_refinement(const tal_t *ctx,
510500
bool solved = false;
511501
const tal_t *this_ctx = tal(ctx, tal_t);
512502

513-
if (!this_ctx)
514-
/* bad allocation */
515-
goto finish;
516-
517503
assert(graph);
518504
assert(excess);
519505
assert(capacity);
@@ -627,9 +613,6 @@ bool simple_mcf(const tal_t *ctx, const struct graph *graph,
627613
s64 *capacity, s64 amount, const s64 *cost)
628614
{
629615
const tal_t *this_ctx = tal(ctx, tal_t);
630-
if (!this_ctx)
631-
/* bad allocation */
632-
goto fail;
633616

634617
assert(graph);
635618
const size_t max_num_arcs = graph_max_num_arcs(graph);
@@ -647,10 +630,6 @@ bool simple_mcf(const tal_t *ctx, const struct graph *graph,
647630
s64 *potential = tal_arrz(this_ctx, s64, max_num_nodes);
648631
s64 *excess = tal_arrz(this_ctx, s64, max_num_nodes);
649632

650-
if (!potential || !excess)
651-
/* bad allocation */
652-
goto fail;
653-
654633
excess[source.idx] = amount;
655634
excess[destination.idx] = -amount;
656635

plugins/askrene/graph.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ struct graph *graph_new(const tal_t *ctx, const size_t max_num_nodes,
4242
struct graph *graph;
4343
graph = tal(ctx, struct graph);
4444

45-
/* bad allocation of graph */
46-
if (!graph)
47-
return graph;
48-
4945
graph->max_num_arcs = max_num_arcs;
5046
graph->max_num_nodes = max_num_nodes;
5147
graph->arc_dual_bit = arc_dual_bit;
@@ -56,12 +52,6 @@ struct graph *graph_new(const tal_t *ctx, const size_t max_num_nodes,
5652
graph->node_adjacency_next =
5753
tal_arr(graph, struct arc, graph->max_num_arcs);
5854

59-
/* bad allocation of graph components */
60-
if (!graph->arc_tail || !graph->node_adjacency_first ||
61-
!graph->node_adjacency_next) {
62-
return tal_free(graph);
63-
}
64-
6555
/* initialize with invalid indexes so that we know these slots have
6656
* never been used, eg. arc/node is newly created */
6757
for (size_t i = 0; i < graph->max_num_arcs; i++)

0 commit comments

Comments
 (0)