Opened 5 years ago

Closed 4 years ago

#10014 closed feature request (fixed)

Data.Array.Base.elems needlessly calls bounds.

Reported by: ekmett Owned by:
Priority: normal Milestone: 8.0.1
Component: Core Libraries Version: 7.8.4
Keywords: Cc: core-libraries-committee@…, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

elems arr = case bounds arr of
    (_l, _u) -> [unsafeAt arr i | i <- [0 .. numElements arr - 1]]

It never uses the result.

I'd propose simplifying it to

elems arr = [unsafeAt arr i | i <- [0 .. numElements arr - 1]]

It appears at some point someone optimized it to use the unsafeAt, but never removed the bounds check.

Change History (3)

comment:1 in reply to:  description Changed 5 years ago by hvr

Replying to ekmett:

It appears at some point someone optimized it to use the unsafeAt, but never removed the bounds check.

that happened here: https://git.haskell.org/packages/array.git/commitdiff/0c4b7d714dd82072ea95c5973dc7160428b93235

comment:2 Changed 4 years ago by thomie

Owner: ekmett deleted

comment:3 Changed 4 years ago by thomie

Cc: ekmett added
Milestone: 8.0.1
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.