@@ -1386,6 +1386,11 @@ class CppcheckData:
13861386 suppressions List of Suppressions
13871387 files Source files for elements occurred in this configuration
13881388
1389+ The configurations property loads all configurations once and keeps them,
1390+ which is best when the configurations are iterated more than once.
1391+ iterconfigurations() parses the dump file on each call but creates one
1392+ configuration at a time, which uses less memory for a single iteration.
1393+
13891394 To iterate through all configurations use such code:
13901395 @code
13911396 data = cppcheckdata.parsedump(...)
@@ -1424,6 +1429,7 @@ def __init__(self, filename):
14241429 self .platform = None
14251430 self .suppressions = []
14261431 self .files = [] # source files for elements occurred in this configuration
1432+ self ._configurations = None # set by the configurations property
14271433
14281434 # Parse general configuration options from <dumps> node, the raw tokens
14291435 # and the suppressions. The configurations are parsed by iterconfigurations.
@@ -1444,14 +1450,26 @@ def __init__(self, filename):
14441450 def configurations (self ):
14451451 """
14461452 Return the list of all available Configuration objects.
1453+ The configurations are loaded on the first access and kept, so later
1454+ accesses and iterconfigurations() do not parse the dump file again.
1455+ All configurations stay in memory as long as this object exists.
14471456 """
1448- return list (self .iterconfigurations ())
1457+ if self ._configurations is None :
1458+ self ._configurations = list (self .iterconfigurations ())
1459+ return self ._configurations
14491460
14501461 def iterconfigurations (self ):
14511462 """
14521463 Create and return iterator for the available Configuration objects.
14531464 The iterator loops over all Configurations in the dump file tree, in document order.
1465+ If the configurations property has been used then the kept configurations
1466+ are returned. Otherwise the dump file is parsed and each configuration is
1467+ created when the iterator reaches it, so a configuration can be freed when
1468+ the caller is done with it. Each call parses the dump file again.
14541469 """
1470+ if self ._configurations is not None :
1471+ yield from self ._configurations
1472+ return
14551473 # Parse the dump file incrementally to avoid large memory consumption.
14561474 # A configuration is returned as soon as its </dump> has been parsed.
14571475 # The garbage collector is only disabled while parsing, not while the
0 commit comments