From c092858ac6b1fa0480b7bf6d05529257b53a436f Mon Sep 17 00:00:00 2001 From: "paulgazz@chromium.org" Date: Tue, 13 Aug 2013 00:46:30 +0000 Subject: This patch uses single BytesInstruction Courgette ops to point to long stretches of the binary file, instead of using one ByteInstruction op, which copies one byte at a time. This reduces memory usages for very large files, since less data is copied, and fewer Instruction classes are constructed. BUG=266068 Review URL: https://chromiumcodereview.appspot.com/22728002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217138 0039d316-1c4b-4281-b951-d872f2087c98 --- courgette/assembly_program.cc | 1 + courgette/disassembler_elf_32.cc | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc index f577b98..021de59 100644 --- a/courgette/assembly_program.cc +++ b/courgette/assembly_program.cc @@ -422,6 +422,7 @@ EncodedProgram* AssemblyProgram::Encode() const { const uint8* byte_values = static_cast(instruction)->byte_values(); uint32 len = static_cast(instruction)->len(); + if (!encoded->AddCopy(len, byte_values)) return NULL; break; diff --git a/courgette/disassembler_elf_32.cc b/courgette/disassembler_elf_32.cc index fc4c379..bfd1ef4 100644 --- a/courgette/disassembler_elf_32.cc +++ b/courgette/disassembler_elf_32.cc @@ -409,13 +409,13 @@ CheckBool DisassemblerElf32::ParseSimpleRegion( const uint8* start = OffsetToPointer(start_file_offset); const uint8* end = OffsetToPointer(end_file_offset); - const uint8* p = start; + // Callers don't guarantee start < end + if (start >= end) return true; - while (p < end) { - if (!program->EmitByteInstruction(*p)) - return false; - ++p; - } + const ptrdiff_t len = end - start; // Works because vars are byte pointers + + if (!program->EmitBytesInstruction(start, len)) + return false; return true; } -- cgit v1.1