summaryrefslogtreecommitdiff
path: root/usr.bin/make/str.h
AgeCommit message (Collapse)Author
2023-06-23make: warn about malformed patterns in ':M', ':N' and '.if make(...)'rillig
These patterns shouldn't occur in practice, as their results are tricky to predict. Generate a warning for now, and maybe an error later. Reviewed by sjg@.
2022-12-05make: inline LazyBuf_AddBytesBetweenrillig
No binary change.
2021-12-15make: in CLEANUP mode, free interned strings at the very endrillig
Noticed by sjg.
2021-12-13make: fix memory leak for filenames in .for loops (since 2013-06-18)rillig
Previously, each time a .for directive pushed its buffer on the input file stack, the current filename was duplicated. This was a waste of memory. The name of a file is typically only used while it is read in. There is one situation when the filename is needed for longer, which is when a target is defined. Since .for loops are implemented as a special form of included files, each .for loop duplicated the current filename as well. $ cat << EOF > for.mk .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .endfor .endfor .endfor .endfor .endfor .endfor .endfor all: @ps -o rsz -p ${.MAKE.PID} EOF $ make-2021.12.13.03.55.16 -r -f for.mk RSZ 10720 $ ./make -r -f for.mk RSZ 1716 The difference is 8 MB, which amounts to 1 million .for loops.
2021-12-12make: remove unused type MFStrrillig
The only binary change is the line number of the assertion in Substring_Sub.
2021-12-12make: fix memory leak in LazyBufrillig
This affects many operations on variable expressions. Those using LazyBuf_Done are affected, those using LazyBuf_DoneGet aren't. $ cat <<'EOF' > lazybuf-memleak.mk .for i in ${:U:range=5} . for j in ${:U:range=1000} . for k in ${:U:range=1000} . if 0 && ${VAR:Dpattern\: that needs unescaping} . endif . endfor . endfor .endfor all: @ps -o vsz -p ${.MAKE.PID} | sed 1d EOF Before using LazyBuf for the modifier ':D': $ make-2021.04.14.16.12.26 -r -f lazybuf-memleak.mk VSZ RSZ 1357136 1336432 Using LazyBuf for the modifier ':D': $ make-2021.04.14.16.59.34 -r -f lazybuf-memleak.mk VSZ RSZ 1590864 1574164 This commit alone allocates around 150 MB more data, which matches 5_000_000 strings * 30 bytes/string. It looks very wrong that the above simple makefile uses 1.3 GB of RAM at all, and it had already done this in 2017, long before LazyBuf was introduced. Before 2017.01.30.02.46.20, the above test makefile reports way smaller numbers, but that's because the modifier ':range' did not exist back then.
2021-12-05make: save a memory allocation in each modifier ':O' and ':u'rillig
No functional change.
2021-12-05make: inline Str_Words into .for loop handlingrillig
This saves one memory allocation and a bit of copying, per .for loop. No functional change.
2021-05-30make: inline str_concat4rillig
This function is only ever used for forming strings of the form "archive(member)". No functional change.
2021-04-14make: let the compiler decide whether to inline string functionsrillig
On x86_64, this reduces the binary size by 2 kB.
2021-04-14make: reduce memory allocations in the modifiers ':D' and ':U'rillig
2021-04-12make: reduce memory allocation and strlen calls in modifier ':from=to'rillig
Previously, SysVMatch was quite verbose and felt like hand-optimized assembler code, which made it difficult to discover the underlying idea of the code. All this code was replaced with two simple calls to Substring_HasPrefix and Substring_HasSuffix. Now that the operands of that modifier are no longer passed as C strings, there is no need to collect all information in a single scan through the word and the pattern. It was not necessary to call Var_Subst unconditionally. Calling it only when the string contains a '$' saves another memory allocation and two string copies (because of the Buf_DoneDataCompact). No functional change.
2021-04-11make: improve performance for LazyBufrillig
The previous O(n^2) time complexity for parsing a long string with many variable expressions was not meant to last for long. I had hoped to fix it within a few minutes, but that will take more time. For now, make LazyBuf simpler by using a traditional C string for the expected part instead of a Substring. This avoids a strlen call per Var_Parse. No functional change, only performance.
2021-04-11make: migrate ParseModifierPart to use Substringrillig
This will reduce memory allocation for modifier parts without the escape characters '$' or '\'. No functional change.
2021-04-11make: avoid unnecessary calls to strlen when evaluating modifiersrillig
No functional change.
2021-04-11make: migrate ModifyWord functions to use Substringrillig
This benefits the modifiers ':T' and ':H' since these scan the word from the end. The SysV modifier '.c=.o' does not benefit yet, this will be done in a follow-up commit. Currently ModifyWords calls strlen for each single word, which degrades performance. This will be cleaned up in a follow-up commit as well. No functional change.
2021-04-11make: add types Substring and LazyBufrillig
These will be used for making the string handling more efficient, avoiding allocations, especially when evaluating variable expressions. Since the string handling has grown quite a bit in the last months, extract it into its own header file. No functional change.