1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:07:36 +00:00

LibELF: Avoid unnecessarily recomputing loop boundaries over and over

This commit is contained in:
Andreas Kling 2020-02-22 11:25:15 +01:00
parent e81bde4a3d
commit 34b81f17c2

View file

@ -225,14 +225,16 @@ private:
template<typename F> template<typename F>
inline void ELFImage::for_each_section(F func) const inline void ELFImage::for_each_section(F func) const
{ {
for (unsigned i = 0; i < section_count(); ++i) auto section_count = this->section_count();
for (unsigned i = 0; i < section_count; ++i)
func(section(i)); func(section(i));
} }
template<typename F> template<typename F>
inline void ELFImage::for_each_section_of_type(unsigned type, F func) const inline void ELFImage::for_each_section_of_type(unsigned type, F func) const
{ {
for (unsigned i = 0; i < section_count(); ++i) { auto section_count = this->section_count();
for (unsigned i = 0; i < section_count; ++i) {
auto& section = this->section(i); auto& section = this->section(i);
if (section.type() == type) { if (section.type() == type) {
if (func(section) == IterationDecision::Break) if (func(section) == IterationDecision::Break)
@ -244,7 +246,8 @@ inline void ELFImage::for_each_section_of_type(unsigned type, F func) const
template<typename F> template<typename F>
inline void ELFImage::RelocationSection::for_each_relocation(F func) const inline void ELFImage::RelocationSection::for_each_relocation(F func) const
{ {
for (unsigned i = 0; i < relocation_count(); ++i) { auto relocation_count = this->relocation_count();
for (unsigned i = 0; i < relocation_count; ++i) {
if (func(relocation(i)) == IterationDecision::Break) if (func(relocation(i)) == IterationDecision::Break)
break; break;
} }
@ -253,7 +256,8 @@ inline void ELFImage::RelocationSection::for_each_relocation(F func) const
template<typename F> template<typename F>
inline void ELFImage::for_each_symbol(F func) const inline void ELFImage::for_each_symbol(F func) const
{ {
for (unsigned i = 0; i < symbol_count(); ++i) { auto symbol_count = this->symbol_count();
for (unsigned i = 0; i < symbol_count; ++i) {
if (func(symbol(i)) == IterationDecision::Break) if (func(symbol(i)) == IterationDecision::Break)
break; break;
} }
@ -262,6 +266,7 @@ inline void ELFImage::for_each_symbol(F func) const
template<typename F> template<typename F>
inline void ELFImage::for_each_program_header(F func) const inline void ELFImage::for_each_program_header(F func) const
{ {
for (unsigned i = 0; i < program_header_count(); ++i) auto program_header_count = this->program_header_count();
for (unsigned i = 0; i < program_header_count; ++i)
func(program_header(i)); func(program_header(i));
} }