From 25a40521c8c35d7da1b5ca9303c6d8a59f90a09f Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 20 Jul 2021 01:02:02 +0100 Subject: [PATCH] (#42) Short circuit char.Repeat count 0 and 1 --- X10D/src/CharExtensions/CharExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/X10D/src/CharExtensions/CharExtensions.cs b/X10D/src/CharExtensions/CharExtensions.cs index 73c36f1..6e45086 100644 --- a/X10D/src/CharExtensions/CharExtensions.cs +++ b/X10D/src/CharExtensions/CharExtensions.cs @@ -21,7 +21,17 @@ namespace X10D { throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0); } - + + if (count == 0) + { + return string.Empty; + } + + if (count == 1) + { + return value.ToString(); + } + return new string(value, count); } }