From 92035ffdba2aebef5c6da7b81cff79e54117f48a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 9 Mar 2016 19:52:08 +0100 Subject: [PATCH] Don't CombineLatest if no need. --- src/Perspex.Styling/Styling/StyleActivator.cs | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Perspex.Styling/Styling/StyleActivator.cs b/src/Perspex.Styling/Styling/StyleActivator.cs index dd2601e0bb..05b97a11ec 100644 --- a/src/Perspex.Styling/Styling/StyleActivator.cs +++ b/src/Perspex.Styling/Styling/StyleActivator.cs @@ -17,18 +17,40 @@ namespace Perspex.Styling public static class StyleActivator { - public static IObservable And(IEnumerable> inputs) + public static IObservable And(IList> inputs) { - return inputs.CombineLatest() - .Select(values => values.All(x => x)) - .DistinctUntilChanged(); + if (inputs.Count == 0) + { + throw new ArgumentException("StyleActivator.And inputs may not be empty."); + } + else if (inputs.Count == 1) + { + return inputs[0]; + } + else + { + return inputs.CombineLatest() + .Select(values => values.All(x => x)) + .DistinctUntilChanged(); + } } - public static IObservable Or(IEnumerable> inputs) + public static IObservable Or(IList> inputs) { - return inputs.CombineLatest() + if (inputs.Count == 0) + { + throw new ArgumentException("StyleActivator.Or inputs may not be empty."); + } + else if (inputs.Count == 1) + { + return inputs[0]; + } + else + { + return inputs.CombineLatest() .Select(values => values.Any(x => x)) .DistinctUntilChanged(); + } } } }