Skip to content

ResourceHelper: verbose conditional list initialization can be a single ternary #127

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug Description

ResourceHelper initializes an empty list and then conditionally reassigns it inside an if block. A single ternary expression is cleaner.

Actual Behavior

// ResourceHelper.cs lines 56-61
var runningServices = new List<string>();
if (stopServices)
{
    runningServices = isCli
        ? _serviceHelper.GetRunningServyCLIServices()
        : _serviceHelper.GetRunningServyUIServices();
}

The initial new List<string>() allocation is wasted when stopServices is true.

Suggested Fix

var runningServices = stopServices
    ? (isCli ? _serviceHelper.GetRunningServyCLIServices() : _serviceHelper.GetRunningServyUIServices())
    : new List<string>();

Environment

  • File: src/Servy.Core/Helpers/ResourceHelper.cs
  • Lines: 56-61

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