Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New validation model: Fixed stack frames being created when already cached #3107

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,17 @@ public static StackFrame GetCurrentStackFrame(
{
// String is allocated, but it goes out of scope immediately after the call
string key = filePath + lineNumber;
StackFrame frame = CachedStackFrames.GetOrAdd(key, new StackFrame(skipFrames, true));
iNinja marked this conversation as resolved.
Show resolved Hide resolved
return frame;

// Try to get the stack frame from the cache,
// otherwise create a new one and add it to the cache
if (!CachedStackFrames.TryGetValue(key, out StackFrame? frame))
{
frame = new StackFrame(skipFrames, true);
CachedStackFrames.TryAdd(key, frame);
}

// By this point the frame cannot be null, but the compiler doesn't know that
return frame!;
}

// ConcurrentDictionary is thread-safe and only locks when adding a new item.
Expand Down
Loading