mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
core_pe: Aah, got it. Performance from the new cache module are now comparable to the old Cython based one.
This commit is contained in:
parent
cc362deb87
commit
cea1ec7641
51
core_pe/modules/cache/cache.c
vendored
51
core_pe/modules/cache/cache.c
vendored
@ -2,6 +2,7 @@
|
|||||||
* Created On: 2010-01-30
|
* Created On: 2010-01-30
|
||||||
* Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
* Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
||||||
*/
|
*/
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "structmember.h"
|
#include "structmember.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
@ -11,7 +12,7 @@
|
|||||||
* a char, which would in turn require me to buffer my chars around,
|
* a char, which would in turn require me to buffer my chars around,
|
||||||
* making the whole process slower.
|
* making the whole process slower.
|
||||||
*/
|
*/
|
||||||
static inline long
|
static long
|
||||||
xchar_to_long(char c)
|
xchar_to_long(char c)
|
||||||
{
|
{
|
||||||
if ((c >= 48) && (c <= 57)) { /* 0-9 */
|
if ((c >= 48) && (c <= 57)) { /* 0-9 */
|
||||||
@ -30,53 +31,45 @@ static PyObject*
|
|||||||
cache_string_to_colors(PyObject *self, PyObject *args)
|
cache_string_to_colors(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
Py_ssize_t char_count;
|
Py_ssize_t char_count, color_count, i;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#", &s, &char_count)) {
|
if (!PyArg_ParseTuple(args, "s#", &s, &char_count)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyList_New(0);
|
color_count = (char_count / 6);
|
||||||
|
result = PyList_New(color_count);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char_count = (char_count / 6) * 6;
|
for (i=0; i<color_count; i++) {
|
||||||
for (i=0; i<char_count; i+=6) {
|
|
||||||
long r, g, b;
|
long r, g, b;
|
||||||
|
Py_ssize_t ci;
|
||||||
PyObject *color_tuple;
|
PyObject *color_tuple;
|
||||||
PyObject *pi;
|
PyObject *pr, *pg, *pb;
|
||||||
|
|
||||||
r = (xchar_to_long(s[i]) << 4) + xchar_to_long(s[i+1]);
|
ci = i * 6;
|
||||||
g = (xchar_to_long(s[i+2]) << 4) + xchar_to_long(s[i+3]);
|
r = (xchar_to_long(s[ci]) << 4) + xchar_to_long(s[ci+1]);
|
||||||
b = (xchar_to_long(s[i+4]) << 4) + xchar_to_long(s[i+5]);
|
g = (xchar_to_long(s[ci+2]) << 4) + xchar_to_long(s[ci+3]);
|
||||||
|
b = (xchar_to_long(s[ci+4]) << 4) + xchar_to_long(s[ci+5]);
|
||||||
|
|
||||||
color_tuple = PyTuple_New(3);
|
pr = PyInt_FromLong(r);
|
||||||
pi = PyInt_FromLong(r);
|
pg = PyInt_FromLong(g);
|
||||||
if (pi == NULL) {
|
pb = PyInt_FromLong(b);
|
||||||
|
if (pb == NULL) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(color_tuple, 0, pi);
|
color_tuple = PyTuple_Pack(3, pr, pg, pb);
|
||||||
pi = PyInt_FromLong(g);
|
if (color_tuple == NULL) {
|
||||||
if (pi == NULL) {
|
Py_DECREF(pr);
|
||||||
Py_DECREF(result);
|
Py_DECREF(pg);
|
||||||
return NULL;
|
Py_DECREF(pb);
|
||||||
}
|
|
||||||
PyTuple_SET_ITEM(color_tuple, 1, pi);
|
|
||||||
pi = PyInt_FromLong(b);
|
|
||||||
if (pi == NULL) {
|
|
||||||
Py_DECREF(result);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyTuple_SET_ITEM(color_tuple, 2, pi);
|
|
||||||
|
|
||||||
if (PyList_Append(result, color_tuple) < 0) {
|
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
PyList_SET_ITEM(result, i, color_tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user