From b8d3b273cbcc7a4130d6786ff157a87a4f383c30 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 30 Sep 2009 15:04:39 +0300 Subject: [PATCH] Take advantage of headerNextTag() in python hdr.keys() - avoids whole lotta unnecessary copying of data, we're only interested in tag numbers here - dont filter out stuff - python consumers can look at i18n data too --- python/header-py.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/python/header-py.c b/python/header-py.c index a2c71a6..cf77431 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -134,39 +134,16 @@ struct hdrObject_s { static PyObject * hdrKeyList(hdrObject * s) { - PyObject * list, *o; - HeaderIterator hi; - rpmtd td = rpmtdNew(); + PyObject * keys = PyList_New(0); + HeaderIterator hi = headerInitIterator(s->h); + rpmTag tag; - list = PyList_New(0); - - hi = headerInitIterator(s->h); - while (headerNext(hi, td)) { - rpmTag tag = rpmtdTag(td); - if (tag == HEADER_I18NTABLE) continue; - - switch (rpmtdType(td)) { - case RPM_BIN_TYPE: - case RPM_INT32_TYPE: - case RPM_CHAR_TYPE: - case RPM_INT8_TYPE: - case RPM_INT16_TYPE: - case RPM_STRING_ARRAY_TYPE: - case RPM_STRING_TYPE: - PyList_Append(list, o=PyInt_FromLong(tag)); - Py_DECREF(o); - break; - case RPM_I18NSTRING_TYPE: /* hum.. ?`*/ - case RPM_NULL_TYPE: - default: - break; - } - rpmtdFreeData(td); + while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) { + PyList_Append(keys, PyInt_FromLong(tag)); } headerFreeIterator(hi); - rpmtdFree(td); - return list; + return keys; } static PyObject * hdrUnload(hdrObject * s, PyObject * args, PyObject *keywords) -- 2.7.4