Use range iteration for some more loops

This commit is contained in:
Kovid Goyal 2019-09-05 00:07:05 +05:30
parent bc68e6e735
commit 1fbfffd772
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 15 deletions

View File

@ -130,9 +130,9 @@ PDFDoc_save_to_fileobj(PDFDoc *self, PyObject *args) {
static PyObject *
PDFDoc_uncompress_pdf(PDFDoc *self, PyObject *args) {
for (TIVecObjects it = self->doc->GetObjects().begin(); it != self->doc->GetObjects().end(); it++) {
if((*it)->HasStream()) {
PdfMemStream* stream = dynamic_cast<PdfMemStream*>((*it)->GetStream());
for (auto &it : self->doc->GetObjects()) {
if(it->HasStream()) {
PdfMemStream* stream = dynamic_cast<PdfMemStream*>(it->GetStream());
stream->Uncompress();
}
}
@ -175,16 +175,13 @@ PDFDoc_image_count(PDFDoc *self, PyObject *args) {
const PdfObject* obj_type = NULL;
const PdfObject* obj_sub_type = NULL;
try {
TCIVecObjects it = self->doc->GetObjects().begin();
while( it != self->doc->GetObjects().end() ) {
if( (*it)->IsDictionary() ) {
obj_type = (*it)->GetDictionary().GetKey( PdfName::KeyType );
obj_sub_type = (*it)->GetDictionary().GetKey( PdfName::KeySubtype );
for (auto &it : self->doc->GetObjects()) {
if( it->IsDictionary() ) {
obj_type = it->GetDictionary().GetKey( PdfName::KeyType );
obj_sub_type = it->GetDictionary().GetKey( PdfName::KeySubtype );
if( ( obj_type && obj_type->IsName() && ( obj_type->GetName().GetName() == "XObject" ) ) ||
( obj_sub_type && obj_sub_type->IsName() && ( obj_sub_type->GetName().GetName() == "Image" ) ) ) count++;
self->doc->FreeObjectMemory( *it );
}
it++;
}
} catch(const PdfError & err) {
podofo_set_exception(err);

View File

@ -170,15 +170,15 @@ list_fonts(PDFDoc *self, PyObject *args) {
pyunique_ptr ans(PyList_New(0));
if (!ans) return NULL;
const PdfVecObjects &objects = self->doc->GetObjects();
for (TCIVecObjects it = objects.begin(); it != objects.end(); it++) {
if ((*it)->IsDictionary()) {
const PdfDictionary &dict = (*it)->GetDictionary();
for (auto &it : objects) {
if (it->IsDictionary()) {
const PdfDictionary &dict = it->GetDictionary();
if (dictionary_has_key_name(dict, PdfName::KeyType, "Font") && dict.HasKey("BaseFont")) {
const std::string &name = dict.GetKey("BaseFont")->GetName().GetName();
const std::string &subtype = dict.GetKey(PdfName::KeySubtype)->GetName().GetName();
const PdfReference &ref = (*it)->Reference();
const PdfReference &ref = it->Reference();
unsigned long num = ref.ObjectNumber(), generation = ref.GenerationNumber();
const PdfObject *descriptor = (*it)->GetIndirectKey("FontDescriptor");
const PdfObject *descriptor = it->GetIndirectKey("FontDescriptor");
pyunique_ptr descendant_font, stream_ref, encoding, w, w2;
PyBytesOutputStream stream_data, to_unicode;
if (dict.HasKey("W")) {