Deep-Phield-Softworks / XeroSum

Isometric, Squad-Based, Real-Time Strategy RPG
0 stars 0 forks source link

Clean up world.py code with use of new dict variable "currentSectionsDict" #4

Closed EricFedrowisch closed 10 years ago

EricFedrowisch commented 10 years ago

I hope to replace several for loops that search thru a list of section objects, checking the section.name value for each with the creation of a dictionary that has the section names as keys that point to the section instance. This would make for shorter code, simpler code. Possibly marginally faster code.

EricFedrowisch commented 10 years ago

In world.py, there are many for loops created like this:

for figure in world.figures:
    for section in self.currentSections:
        if figure.section == section.name:
            //do stuff

I feel these for loops probably create unnecessary overhead. I am going to try and use a dictionary that is updated with the section names as keys that will be updated at the same time the sections are loading. Something like this:

for figure in world.figures:
    if figure.section in currentSectionsDict:
         //do stuff

This is shorter and uses a dictionary lookup in an existing hash table which I think is probably much faster than initializing a for loop to search through the current sections.

EricFedrowisch commented 10 years ago

Imp'd.