mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 17:15:28 +08:00 
			
		
		
		
	using loop instead of linq
In both of these loops context is captured preventing caching of the lambda. this results in a pretty significant amount of allocations especially with progress bars that constantly are remeasuring
This commit is contained in:
		 Phil Scott
					Phil Scott
				
			
				
					committed by
					
						 Patrik Svensson
						Patrik Svensson
					
				
			
			
				
	
			
			
			 Patrik Svensson
						Patrik Svensson
					
				
			
						parent
						
							c64884854f
						
					
				
				
					commit
					bff3438a5a
				
			| @@ -8,7 +8,13 @@ namespace Spectre.Console | ||||
|     { | ||||
|         public static int GetCellLength(RenderContext context, string text) | ||||
|         { | ||||
|             return text.Sum(rune => GetCellLength(context, rune)); | ||||
|             var sum = 0; | ||||
|             foreach (var rune in text) | ||||
|             { | ||||
|                 sum += GetCellLength(context, rune); | ||||
|             } | ||||
|  | ||||
|             return sum; | ||||
|         } | ||||
|  | ||||
|         public static int GetCellLength(RenderContext context, char rune) | ||||
|   | ||||
| @@ -135,7 +135,13 @@ namespace Spectre.Console.Rendering | ||||
|                 throw new ArgumentNullException(nameof(segments)); | ||||
|             } | ||||
|  | ||||
|             return segments.Sum(segment => segment.CellCount(context)); | ||||
|             var sum = 0; | ||||
|             foreach (var segment in segments) | ||||
|             { | ||||
|                 sum += segment.CellCount(context); | ||||
|             } | ||||
|  | ||||
|             return sum; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user