[vala/wip/foreach: 4/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: 4/7] vala: Avoid taking extra reference of foreach collection for index iteration
- Date: Mon, 9 Nov 2020 18:28:16 +0000 (UTC)
commit 20c9c296c6f24d420d54b4d79278b13518357cc9
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 7d421c711..57ac378b1 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -208,7 +208,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_property.name, 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]