Skip to content

Commit 13d5399

Browse files
committed
Introduce HashingStorageGetItemStringKey.
1 parent 9a37f94 commit 13d5399

3 files changed

Lines changed: 48 additions & 7 deletions

File tree

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.nodes.PGuards;
7070
import com.oracle.graal.python.nodes.PNodeWithContext;
7171
import com.oracle.graal.python.nodes.PRaiseNode;
72+
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromPythonObjectNode;
7273
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
7374
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
7475
import com.oracle.graal.python.nodes.util.CastBuiltinStringToTruffleStringNode;
@@ -146,6 +147,46 @@ static Object foreign(Node inliningTarget, ForeignHashingStorage self, Object ke
146147
}
147148
}
148149

150+
@GenerateUncached
151+
@GenerateInline
152+
@GenerateCached(false)
153+
public abstract static class HashingStorageGetItemStringKey extends Node {
154+
public abstract Object execute(Node inliningTarget, HashingStorage self, TruffleString key);
155+
156+
@Specialization
157+
static Object economicMap(Node inliningTarget, EconomicMapStorage self, TruffleString key,
158+
@Cached TruffleString.HashCodeNode hashCodeNode,
159+
@Cached ObjectHashMap.GetNode getNode) {
160+
return getNode.execute(null, inliningTarget, self.map, key, PyObjectHashNode.hash(key, hashCodeNode));
161+
}
162+
163+
@Specialization
164+
static Object dom(Node inliningTarget, DynamicObjectStorage self, TruffleString key,
165+
@Cached(inline = false) ReadAttributeFromPythonObjectNode readKey,
166+
@Cached InlinedConditionProfile noValueProfile) {
167+
return DynamicObjectStorage.GetItemNode.string(inliningTarget, self, key, -1, readKey, noValueProfile);
168+
}
169+
170+
@Specialization
171+
@SuppressWarnings("unused")
172+
static Object empty(EmptyStorage self, TruffleString key) {
173+
return null;
174+
}
175+
176+
@Specialization
177+
@InliningCutoff
178+
static Object keywords(Node inliningTarget, KeywordsStorage self, TruffleString key,
179+
@Cached GetKeywordsStorageItemNode getNode) {
180+
return getNode.execute(null, inliningTarget, self, key, -1);
181+
}
182+
183+
@Specialization
184+
static Object foreign(Node inliningTarget, ForeignHashingStorage self, TruffleString key,
185+
@Cached ForeignHashingStorage.GetNode getNode) {
186+
return getNode.execute(inliningTarget, self, key);
187+
}
188+
}
189+
149190
@GenerateUncached
150191
@GenerateInline
151192
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromModuleNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -41,7 +41,7 @@
4141
package com.oracle.graal.python.nodes.attributes;
4242

4343
import com.oracle.graal.python.builtins.objects.PNone;
44-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItem;
44+
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItemStringKey;
4545
import com.oracle.graal.python.builtins.objects.module.PythonModule;
4646
import com.oracle.graal.python.nodes.PNodeWithContext;
4747
import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
@@ -74,7 +74,7 @@ public static ReadAttributeFromModuleNode getUncached() {
7474
static Object readModuleAttribute(PythonModule object, TruffleString key,
7575
@Bind Node inliningTarget,
7676
@Cached GetDictIfExistsNode getDict,
77-
@Cached HashingStorageGetItem getItem) {
77+
@Cached HashingStorageGetItemStringKey getItem) {
7878
var dict = getDict.execute(object);
7979
Object value = getItem.execute(inliningTarget, dict.getDictStorage(), key);
8080
if (value == null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromObjectNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.PNone;
4444
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
45-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItem;
45+
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageGetItemStringKey;
4646
import com.oracle.graal.python.builtins.objects.dict.PDict;
4747
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4848
import com.oracle.graal.python.nodes.PNodeWithContext;
@@ -90,7 +90,7 @@ static Object readObjectAttribute(PythonObject object, TruffleString key,
9090
@Cached InlinedConditionProfile profileHasDict,
9191
@Exclusive @Cached GetDictIfExistsNode getDict,
9292
@Cached ReadAttributeFromPythonObjectNode readAttributeFromPythonObjectNode,
93-
@Exclusive @Cached HashingStorageGetItem getItem) {
93+
@Exclusive @Cached HashingStorageGetItemStringKey getItem) {
9494
var dict = getDict.execute(object);
9595
if (profileHasDict.profile(inliningTarget, dict == null)) {
9696
return readAttributeFromPythonObjectNode.execute(object, key);
@@ -108,10 +108,10 @@ static Object readObjectAttribute(PythonObject object, TruffleString key,
108108
static Object readNativeObject(PythonAbstractNativeObject object, TruffleString key,
109109
@Bind Node inliningTarget,
110110
@Exclusive @Cached GetDictIfExistsNode getDict,
111-
@Exclusive @Cached HashingStorageGetItem getItem) {
111+
@Exclusive @Cached HashingStorageGetItemStringKey getItem) {
112112
PDict dict = getDict.execute(object);
113113
if (dict != null) {
114-
Object result = getItem.execute(null, inliningTarget, dict.getDictStorage(), key);
114+
Object result = getItem.execute(inliningTarget, dict.getDictStorage(), key);
115115
if (result != null) {
116116
return result;
117117
}

0 commit comments

Comments
 (0)