Skip to content

Commit 630cc16

Browse files
committed
re-use cells for non-empty list construction
1 parent 795cebb commit 630cc16

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: Network/Socket/Info.hsc

+5-6
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,15 @@ followAddrInfo ptr_ai
317317
| otherwise = do
318318
a <- peek ptr_ai
319319
ptr <- (# peek struct addrinfo, ai_next) ptr_ai
320-
go ptr a
320+
(a :|) <$> go id ptr
321321
where
322-
go :: Ptr AddrInfo -> AddrInfo -> IO (NonEmpty AddrInfo)
323-
go ptr a
324-
| ptr == nullPtr = return $ NE.singleton a
322+
go :: ([AddrInfo] -> [AddrInfo]) -> Ptr AddrInfo -> IO [AddrInfo]
323+
go acc ptr
324+
| ptr == nullPtr = return $ acc []
325325
| otherwise = do
326326
a' <- peek ptr
327327
ptr' <- (# peek struct addrinfo, ai_next) ptr
328-
as <- go ptr' a'
329-
return $ NE.cons a as
328+
go (acc . (a':)) ptr'
330329

331330
foreign import ccall safe "hsnet_getaddrinfo"
332331
c_getaddrinfo :: CString -> CString -> Ptr AddrInfo -> Ptr (Ptr AddrInfo)

0 commit comments

Comments
 (0)