nanochess / pretty6502

A pretty printer for 6502, Z80, CP1610, TMS9900, and 8088 assembler code
BSD 2-Clause "Simplified" License
34 stars 4 forks source link

Suggestion to optimize read scan #1

Closed robertlipe closed 6 years ago

robertlipe commented 6 years ago

https://github.com/nanochess/pretty6502/blob/192644256c104e5eee72d7c2e98bfff19629dcab/pretty6502.c#L209

Minor, but instead of looping and reading every string, consider stat or fstat with the file handle. The OS will populate a struct stat. The member you need is st_size. You'll have to think about the tradeoff of st_size representing every byte on disk (carriage return/newline) while your approach might generate slightly smaller allocations. Reading it and then immediately copying it can be pretty harsh on the data cache and the block I/O systems; This could be mad faster still by using mmap() (Windows calls it something else, but it's there on all the UNIX-y systems) and just parsing the data in place via pointer.

Just a tip...

nanochess commented 6 years ago

I made the source to be read in one step.