Quantcast
Viewing all articles
Browse latest Browse all 106942

RSRP-288020: convert to LINQ - incomplete reduction

Reporter Image may be NSFW.
Clik here to view.
Jakub Jiricek (jakub.jiricek@vodafone.com)
Jakub Jiricek (jakub.jiricek@vodafone.com)
Created Jan 26, 2012 6:39:44 PM
Updated Jan 26, 2012 6:39:44 PM
Priority Normal
Type Bug
Fix versions No Fix versions
State Submitted
Assignee Sergey Shkredov (serjic.shkredov)
Subsystem Refactoring
Affected versions 6.1.1
Fixed in build No Fixed in build
in the most recent 6.1.40.6, the code
    private int test1(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values)
      {
        if (val > max) max = val;
      }
      return max;
    }

    private int test2(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values)
      {
        if (val >= max) max = val;
      }
      return max;
    }

    private int test3(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values)
      {
        max = val > max ? val : max;
      }
      return max;
    }

    private int test4(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values)
      {
        max = val >= max ? val : max;
      }
      return max;
    }

    private int test5(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values)
      {
        max = Math.Max(max, val);
      }
      return max;
    }


would be converted (using "Convert into LINQ-Expression") to

    private int test1(IEnumerable<int> values)
    {
      return values.Concat(new[] {0}).Max();
    }

    private int test2(IEnumerable<int> values)
    {
      int max = 0;
      foreach (int val in values.Where(val => val >= max))
      {
        max = val;
      }
      return max;
    }

    private int test3(IEnumerable<int> values)
    {
      return values.Concat(new[] {0}).Max();
    }

    private int test4(IEnumerable<int> values)
    {
      return values.Concat(new[] {0}).Max();
    }

    private int test5(IEnumerable<int> values)
    {
      return values.Concat(new[] {0}).Max();
    }


If I am not missing anything, the test2 shoud be reducible the same way as the other four methods.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>