arithy / packcc

A parser generator for C
Other
349 stars 29 forks source link

Skip unnecessary reallocations #16

Closed dolik-rce closed 3 years ago

dolik-rce commented 3 years ago

I've started to look into ways to optimize parsers generated by packcc in ctags (see https://github.com/universal-ctags/ctags/issues/2878, if you are interested). The first thing I have discovered is that there is a few places where resizing code is called even though the size is not changed at all.

This PR adds check for these useless resizes and eliminates them. My benchmarks show, that this makes the parser about 13% faster.

arithy commented 3 years ago

Thanks! I'll apply the same modification to the code of packcc itself as well as its generated code.

dolik-rce commented 3 years ago

Thanks for merging this @arithy!

I'll apply the same modification to the code of packcc itself

Actually I didn't even notice that similar pattern is used in the packcc itself, since I was only interested in the speed of the generated code. Well, next time I'll try think of that too.