From 6b63e032a9c88d2c6e9cf0e8b73099959dfe6701 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Fri, 4 Jun 2021 14:57:02 +0200 Subject: [PATCH] C#: Populate labels earlier --- csharp/extractor/Semmle.Extraction/Context.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction/Context.cs b/csharp/extractor/Semmle.Extraction/Context.cs index b08fb98fc553..410b3c6980ac 100644 --- a/csharp/extractor/Semmle.Extraction/Context.cs +++ b/csharp/extractor/Semmle.Extraction/Context.cs @@ -35,12 +35,14 @@ public class Context // A recursion guard against writing to the trap file whilst writing an id to the trap file. private bool writingLabel = false; + private readonly Queue labelQueue = new(); + protected void DefineLabel(IEntity entity) { if (writingLabel) { // Don't define a label whilst writing a label. - PopulateLater(() => DefineLabel(entity)); + labelQueue.Enqueue(entity); } else { @@ -52,6 +54,10 @@ protected void DefineLabel(IEntity entity) finally { writingLabel = false; + if (labelQueue.Any()) + { + DefineLabel(labelQueue.Dequeue()); + } } } }