#19597: General code cleanup: avoid code like x.__eq__(y)
-------------------------------------+-------------------------------------
       Reporter:  jdemeyer           |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.10
      Component:  misc               |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Jeroen Demeyer     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/jdemeyer/general_code_cleanup__avoid_x___eq___y_|  
b2094a8a1cedafab73db0ed7653db3112982cec4
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by jdemeyer):

 Replying to [comment:9 vdelecroix]:
 > `groups/perm_gps/permgroup.py`: Is there any difference between
 `list(L)` and `[x for x in L]`? As far as I understand `list` is smarter
 and call for `__len__` to allocate directly the right amount of memory.
 Whereas the second uses `.append`.

 That's true in general, however: there is no `__len__` implemented in this
 case. There is a generic `__len__` coming from `Parent` but that calls
 `len(self.list())` which would lead to an infinite loop. So I think that
 `[x for x in L]` is the most efficient way to create the list here.

 That's probably also the reason the old code was written like
 `list(self.__iter__())` and not `list(self)`.

--
Ticket URL: <http://trac.sagemath.org/ticket/19597#comment:11>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to