[vala/wip/foreach: 1/7] vala: Avoid taking extra reference of foreach collection for index iteration
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/foreach: 1/7] vala: Avoid taking extra reference of foreach collection for index iteration
- Date: Tue, 10 Nov 2020 07:47:00 +0000 (UTC)
commit d45eee6e8c233e15383b57f1dd0706f93084ccc2
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Nov 9 15:38:38 2020 +0100
vala: Avoid taking extra reference of foreach collection for index iteration
vala/valaforeachstatement.vala | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala
index da80b24aa..258a81dae 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -205,7 +205,11 @@ public class Vala.ForeachStatement : Block {
return false;
}
- add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_list".printf
(variable_name), collection, source_reference), source_reference));
+ var list_type = collection_type.copy ();
+ if (collection.symbol_reference is Variable) {
+ list_type.value_owned = false;
+ }
+ add_statement (new DeclarationStatement (new LocalVariable (list_type, "_%s_list".printf
(variable_name), collection, source_reference), source_reference));
add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_size".printf
(variable_name), new MemberAccess (new MemberAccess.simple ("_%s_list".printf (variable_name),
source_reference), "size", source_reference), source_reference), source_reference));
add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_index".printf
(variable_name), new UnaryExpression (UnaryOperator.MINUS, new IntegerLiteral ("1", source_reference),
source_reference), source_reference), source_reference));
var next = new UnaryExpression (UnaryOperator.INCREMENT, new MemberAccess.simple
("_%s_index".printf (variable_name), source_reference), source_reference);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]