BUTLAST counts conses before copying whole list

Bug #1245697 reported by Johan Andersson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Low
Unassigned

Bug Description

BUTLAST counts the conses of the argument list before checking if n is zero, in which case the entire list will be copied. The zerop check can be done before counting the conses, as in NBUTLAST. Also, the similar cases of BUTLAST and NBUTLAST can be made clearer.

Regression tests already exist in tests/list.pure.lisp

Tags: review
Revision history for this message
Johan Andersson (nilsjohanandersson) wrote :
Revision history for this message
Paul Khuong (pvk) wrote :

I'll commit this after the freeze.

Thank you!

Changed in sbcl:
status: New → Confirmed
importance: Undecided → Low
assignee: nobody → Paul Khuong (pvk)
status: Confirmed → In Progress
Revision history for this message
Johan Andersson (nilsjohanandersson) wrote :

You might want to consider this patch instead. It does BUTLAST and NBUTLAST for (< 0 n) without counting the conses beforehand, by looping with two variables down the list N conses apart.

I'm not sure about the style, the names of the variables or if it's worth the fuss. But there you are.

Revision history for this message
Paul Khuong (pvk) wrote :

I tried to preserve the logic, but eliminated the counter variable I. It's applied in 498ec57 ([N]BUTLAST perform a single pass over the list).

I also yanked the docstrings out: we try not to duplicate the CLHS.

Thank you!

Changed in sbcl:
status: In Progress → Fix Committed
assignee: Paul Khuong (pvk) → nobody
Revision history for this message
Johan Andersson (nilsjohanandersson) wrote :

That's neat! Thanks.

Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.