Skip to content

EnvironmentVariableParser: list allocated before guard clause — use early return #128

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug Description

EnvironmentVariableParser.Parse() allocates a List<EnvironmentVariable> before the null/empty input check. Moving the guard clause first avoids the unnecessary allocation on empty input.

Actual Behavior

// EnvironmentVariableParser.cs lines 19-24
var result = new List<EnvironmentVariable>();

if (string.IsNullOrEmpty(input))
    return result;

The list is allocated even when input is null or empty.

Suggested Fix

if (string.IsNullOrEmpty(input))
    return new List<EnvironmentVariable>();

var result = new List<EnvironmentVariable>();

Or with modern C# collection expressions:

if (string.IsNullOrEmpty(input))
    return [];

Environment

  • File: src/Servy.Core/EnvironmentVariables/EnvironmentVariableParser.cs
  • Lines: 19-24

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions