[ https://issues.apache.org/jira/browse/ARROW-2354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16414780#comment-16414780 ]
ASF GitHub Bot commented on ARROW-2354: --------------------------------------- cpcloud closed pull request #1794: ARROW-2354: [C++] Make PyDecimal_Check() faster URL: https://github.com/apache/arrow/pull/1794 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/cpp/src/arrow/python/helpers.cc b/cpp/src/arrow/python/helpers.cc index 5719af6f3..63fee54b6 100644 --- a/cpp/src/arrow/python/helpers.cc +++ b/cpp/src/arrow/python/helpers.cc @@ -227,12 +227,16 @@ Status UInt64FromPythonInt(PyObject* obj, uint64_t* out) { } bool PyDecimal_Check(PyObject* obj) { - // TODO(phillipc): Is this expensive? - OwnedRef Decimal; - Status status = ImportDecimalType(&Decimal); - DCHECK_OK(status); - const int32_t result = PyObject_IsInstance(obj, Decimal.obj()); - DCHECK_NE(result, -1) << " error during PyObject_IsInstance check"; + static OwnedRef decimal_type; + if (!decimal_type.obj()) { + Status status = ImportDecimalType(&decimal_type); + DCHECK_OK(status); + DCHECK(PyType_Check(decimal_type.obj())); + } + // PyObject_IsInstance() is slower as it has to check for virtual subclasses + const int result = + PyType_IsSubtype(Py_TYPE(obj), reinterpret_cast<PyTypeObject*>(decimal_type.obj())); + DCHECK_NE(result, -1) << " error during PyType_IsSubtype check"; return result == 1; } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [C++] PyDecimal_Check() is much too slow > ---------------------------------------- > > Key: ARROW-2354 > URL: https://issues.apache.org/jira/browse/ARROW-2354 > Project: Apache Arrow > Issue Type: Bug > Components: C++, Python > Affects Versions: 0.9.0 > Reporter: Antoine Pitrou > Assignee: Antoine Pitrou > Priority: Major > Labels: pull-request-available > Fix For: 0.10.0 > > > See https://github.com/apache/arrow/issues/1792 -- This message was sent by Atlassian JIRA (v7.6.3#76005)