Skip to content

Commit 98ad0e6

Browse files
committed
Address review feedback
1 parent 142807f commit 98ad0e6

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static PyObject * _PyUnicode_FromUCS1(const Py_UCS1 *s, Py_ssize_t size);
9393
static PyObject * _PyUnicode_FromUCS2(const Py_UCS2 *s, Py_ssize_t size);
9494
static PyObject * _PyUnicode_FromUCS4(const Py_UCS4 *s, Py_ssize_t size);
9595

96-
static inline void* convert_errors(const char *errors) {
96+
static MUST_INLINE void* convert_errors(const char *errors) {
9797
return errors != NULL ? polyglot_from_string(errors, SRC_CS) : polyglot_from_string("strict", SRC_CS);
9898
}
9999

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,18 @@ public abstract static class SourceHashNode extends PythonBinaryClinicBuiltinNod
388388
@Specialization
389389
PBytes run(long magicNumber, Object sourceBuffer,
390390
@Cached BytesNodes.HashBufferNode hashBufferNode) {
391+
long sourceHash = hashBufferNode.execute(sourceBuffer);
392+
return factory().createBytes(computeHash(magicNumber, sourceHash));
393+
}
394+
395+
@TruffleBoundary
396+
private static byte[] computeHash(long magicNumber, long sourceHash) {
391397
byte[] hash = new byte[Long.BYTES];
392-
long hashCode = magicNumber ^ hashBufferNode.execute(sourceBuffer);
398+
long hashCode = magicNumber ^ sourceHash;
393399
for (int i = 0; i < hash.length; i++) {
394400
hash[i] = (byte) (hashCode << (8 * i));
395401
}
396-
return factory().createBytes(hash);
402+
return hash;
397403
}
398404

399405
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,11 @@ static long hashDirect(Object buffer,
869869
PythonBufferAccessLibrary.assertIsBuffer(buffer);
870870
int len = bufferLib.getBufferLength(buffer);
871871
byte[] array = bufferLib.getInternalByteArray(buffer);
872+
return computeHash(len, array);
873+
}
874+
875+
@TruffleBoundary
876+
private static int computeHash(int len, byte[] array) {
872877
int result = 1;
873878
for (int i = 0; i < len; i++) {
874879
result = 31 * result + array[i];

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,12 @@ abstract static class GetModuleNode extends PythonBinaryBuiltinNode {
178178
Object getModule(VirtualFrame frame, PBuiltinMethod self, @SuppressWarnings("unused") PNone none,
179179
@Cached PyObjectLookupAttr lookup,
180180
@CachedLibrary("self") DynamicObjectLibrary dylib) {
181+
// No profiling, performance here is not very important
181182
Object module = dylib.getOrDefault(self, __MODULE__, PNone.NO_VALUE);
182183
if (module != PNone.NO_VALUE) {
183184
return module;
184185
}
185186
if (self.getSelf() instanceof PythonModule) {
186-
/*
187-
* 'getThreadStateNode' acts as a branch profile. This indirect call is done to
188-
* easily support calls to this builtin with and without virtual frame, and because
189-
* we don't care much about the performance here anyway
190-
*/
191187
PythonLanguage language = getLanguage();
192188
Object state = IndirectCallContext.enter(frame, language, getContext(), this);
193189
try {

0 commit comments

Comments
 (0)