1
1
/*
2
- * Copyright (c) 2017, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2017, 2019 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
40
40
*/
41
41
package com .oracle .graal .python .nodes .generator ;
42
42
43
- import com .oracle .graal .python .builtins .objects .common .HashingStorage . Equivalence ;
44
- import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes . PythonEquivalence ;
43
+ import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
44
+ import com .oracle .graal .python .builtins .objects .common .HashingStorageNodes ;
45
45
import com .oracle .graal .python .builtins .objects .dict .PDict ;
46
46
import com .oracle .graal .python .nodes .expression .ExpressionNode ;
47
47
import com .oracle .truffle .api .CompilerDirectives ;
48
+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
48
49
import com .oracle .truffle .api .frame .VirtualFrame ;
49
50
import com .oracle .truffle .api .nodes .ExplodeLoop ;
50
51
51
52
public final class DictConcatNode extends ExpressionNode {
52
53
53
54
@ Children final ExpressionNode [] mappables ;
54
- @ Child private Equivalence equivalenceNode ;
55
-
56
- protected Equivalence getEquivalence () {
57
- if (equivalenceNode == null ) {
58
- CompilerDirectives .transferToInterpreterAndInvalidate ();
59
- equivalenceNode = insert (new PythonEquivalence ());
60
- }
61
- return equivalenceNode ;
62
- }
55
+ @ Child private HashingStorageNodes .SetItemNode setItemNode ;
56
+ @ Child private HashingStorageNodes .GetItemNode getItemNode ;
63
57
64
58
private DictConcatNode (ExpressionNode ... mappablesNodes ) {
65
59
this .mappables = mappablesNodes ;
@@ -75,12 +69,25 @@ public Object execute(VirtualFrame frame) {
75
69
first = expectDict (n .execute (frame ));
76
70
} else {
77
71
other = expectDict (n .execute (frame ));
78
- first . getDictStorage (). addAll ( other . getDictStorage (), getEquivalence () );
72
+ addAllToDict ( first , other );
79
73
}
80
74
}
81
75
return first ;
82
76
}
83
77
78
+ @ TruffleBoundary
79
+ private void addAllToDict (PDict dict , PDict other ) {
80
+ if (setItemNode == null || getItemNode == null ) {
81
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
82
+ setItemNode = insert (HashingStorageNodes .SetItemNode .create ());
83
+ getItemNode = insert (HashingStorageNodes .GetItemNode .create ());
84
+ }
85
+ HashingStorage dictStorage = dict .getDictStorage ();
86
+ for (Object key : other .keys ()) {
87
+ setItemNode .execute (dictStorage , key , getItemNode .execute (other .getDictStorage (), key ));
88
+ }
89
+ }
90
+
84
91
private static PDict expectDict (Object first ) {
85
92
if (!(first instanceof PDict )) {
86
93
CompilerDirectives .transferToInterpreter ();
0 commit comments