Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10964

List.minus() slow for Numbers

    XMLWordPrintableJSON

Details

    Description

      In List.minus() is a n*LOG(n) version for comparable objects. Only for numbers, there is a dedicated slower n^2*LOG(n) version. Is there a reason for this? It exists since 2.4.0 and hasn't changed much since then. Here is part of the code from version 4.0.9:

       

      // if (nlgnSort && (head instanceof Comparable)) {
          //n*LOG(n) version
          Set<T> answer;
          if (head instanceof Number) {
              answer = new TreeSet<>(comparator);
              answer.addAll(self1);
              for (T t : self1) {
                  if (t instanceof Number) {
                      for (Object t2 : removeMe1) {
                          if (t2 instanceof Number) {
                              if (comparator.compare(t, (T) t2) == 0)
                                  answer.remove(t);
                          }
                      }
                  } else {
                      if (removeMe1.contains(t))
                          answer.remove(t);
                  }
              }
          } else {
              answer = new TreeSet<>(comparator);
              answer.addAll(self1);
              answer.removeAll(removeMe1);
          }
      
          for (T o : self1) {
              if (answer.contains(o))
                  ansCollection.add(o);
          }
      } else {
          //n*n version 

      I fail to see why the whole extra block for numbers beginning with

      if (head instanceof Number) { 

      is necessary.

       

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              iwilms Ingo Wilms
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified