546
546
static Py_ssize_t
547
547
load_lines(PyObject *orig, struct line **lines)
549
Py_ssize_t size, i, j, tuple_len;
550
Py_ssize_t total_len;
549
Py_ssize_t size, i, j, tuple_len, cur_len, total_len;
553
550
struct line *line;
554
PyObject *seq, *item;
551
PyObject *seq, *item, *subitem;
556
553
seq = PySequence_Fast(orig, "sequence expected");
557
554
if (seq == NULL) {
574
571
for (i = 0; i < size; i++) {
575
572
item = PySequence_Fast_GET_ITEM(seq, i);
576
573
if (PyString_Check(item)) {
577
// we could use the 'djb2' hash here if we find it is better than
578
// PyObject_Hash, however it seems a lot slower to compute, and
579
// doesn't give particularly better results
574
/* we could use the 'djb2' hash here if we find it is better than
575
PyObject_Hash, however it seems measurably slower to compute,
576
and doesn't give particularly better results
580
578
line->len = PyString_GET_SIZE(item);
581
579
} else if (PyTuple_Check(item)) {
583
581
tuple_len = PyObject_Length(item);
584
582
for (j = 0; j < tuple_len; ++j) {
585
total_len += PyObject_Length(PySequence_Fast_GET_ITEM(item, j));
583
subitem = PySequence_Fast_GET_ITEM(item, j);
584
cur_len = PyObject_Length(subitem);
589
total_len += cur_len;
587
591
line->len = total_len;
590
line->len = PyObject_Length(item);
594
cur_len = PyObject_Length(item);
592
601
line->data = item;
593
602
line->hash = PyObject_Hash(item);
603
if (line->hash == (-1)) {
604
/* Propogate the hash exception */
594
607
line->next = SENTINEL;