Remove unnecessary fromIntegral calls
authorsimonpj@microsoft.com <unknown>
Tue, 16 Nov 2010 17:24:51 +0000 (17:24 +0000)
committersimonpj@microsoft.com <unknown>
Tue, 16 Nov 2010 17:24:51 +0000 (17:24 +0000)
GHC/Conc/IO.hs
GHC/IO/BufferedIO.hs
GHC/IO/FD.hs
GHC/IO/Handle/FD.hs
GHC/IO/Handle/Text.hs
System/IO.hs

index 785239c..590e3ab 100644 (file)
@@ -107,7 +107,7 @@ threadDelay time
   | threaded  = Event.threadDelay time
 #endif
   | otherwise = IO $ \s ->
-        case fromIntegral time of { I# time# ->
+        case time of { I# time# ->
         case delay# time# s of { s' -> (# s', () #)
         }}
 
index e1dc79d..584f5a7 100644 (file)
@@ -22,7 +22,6 @@ import GHC.Base
 import GHC.Ptr
 import Data.Word
 import GHC.Num
-import GHC.Real
 import Data.Maybe
 -- import GHC.IO
 import GHC.IO.Device as IODevice
@@ -93,9 +92,8 @@ readBuf :: RawIO dev => dev -> Buffer Word8 -> IO (Int, Buffer Word8)
 readBuf dev bbuf = do
   let bytes = bufferAvailable bbuf
   res <- withBuffer bbuf $ \ptr ->
-             RawIO.read dev (ptr `plusPtr` bufR bbuf) (fromIntegral bytes)
-  let res' = fromIntegral res
-  return (res', bbuf{ bufR = bufR bbuf + res' })
+             RawIO.read dev (ptr `plusPtr` bufR bbuf) bytes
+  return (res, bbuf{ bufR = bufR bbuf + res })
          -- zero indicates end of file
 
 readBufNonBlocking :: RawIO dev => dev -> Buffer Word8
@@ -105,16 +103,16 @@ readBufNonBlocking :: RawIO dev => dev -> Buffer Word8
 readBufNonBlocking dev bbuf = do
   let bytes = bufferAvailable bbuf
   res <- withBuffer bbuf $ \ptr ->
-           IODevice.readNonBlocking dev (ptr `plusPtr` bufR bbuf) (fromIntegral bytes)
+           IODevice.readNonBlocking dev (ptr `plusPtr` bufR bbuf) bytes
   case res of
      Nothing -> return (Nothing, bbuf)
-     Just n  -> return (Just n, bbuf{ bufR = bufR bbuf + fromIntegral n })
+     Just n  -> return (Just n, bbuf{ bufR = bufR bbuf + n })
 
 writeBuf :: RawIO dev => dev -> Buffer Word8 -> IO (Buffer Word8)
 writeBuf dev bbuf = do
   let bytes = bufferElems bbuf
   withBuffer bbuf $ \ptr ->
-      IODevice.write dev (ptr `plusPtr` bufL bbuf) (fromIntegral bytes)
+      IODevice.write dev (ptr `plusPtr` bufL bbuf) bytes
   return bbuf{ bufL=0, bufR=0 }
 
 -- XXX ToDo
@@ -122,6 +120,5 @@ writeBufNonBlocking :: RawIO dev => dev -> Buffer Word8 -> IO (Int, Buffer Word8
 writeBufNonBlocking dev bbuf = do
   let bytes = bufferElems bbuf
   res <- withBuffer bbuf $ \ptr ->
-            IODevice.writeNonBlocking dev (ptr `plusPtr` bufL bbuf)
-                                      (fromIntegral bytes)
+            IODevice.writeNonBlocking dev (ptr `plusPtr` bufL bbuf) bytes
   return (res, bufferAdjustL res bbuf)
index 2242ee6..4c3e117 100644 (file)
@@ -156,7 +156,7 @@ openFile filepath iomode =
     -- always returns EISDIR if the file is a directory and was opened
     -- for writing, so I think we're ok with a single open() here...
     fd <- throwErrnoIfMinus1Retry "openFile"
-                (c_open f (fromIntegral oflags) 0o666)
+                (c_open f oflags 0o666)
 
     (fD,fd_type) <- mkFD fd iomode Nothing{-no stat-}
                             False{-not a socket-} 
@@ -394,9 +394,8 @@ setRaw fd raw = System.Posix.Internals.setCooked (fdFD fd) (not raw)
 -- Reading and Writing
 
 fdRead :: FD -> Ptr Word8 -> Int -> IO Int
-fdRead fd ptr bytes = do
-  r <- readRawBufferPtr "GHC.IO.FD.fdRead" fd ptr 0 (fromIntegral bytes)
-  return (fromIntegral r)
+fdRead fd ptr bytes
+  = readRawBufferPtr "GHC.IO.FD.fdRead" fd ptr 0 (fromIntegral bytes)
 
 fdReadNonBlocking :: FD -> Ptr Word8 -> Int -> IO (Maybe Int)
 fdReadNonBlocking fd ptr bytes = do
@@ -404,7 +403,7 @@ fdReadNonBlocking fd ptr bytes = do
            0 (fromIntegral bytes)
   case r of
     (-1) -> return (Nothing)
-    n    -> return (Just (fromIntegral n))
+    n    -> return (Just n)
 
 
 fdWrite :: FD -> Ptr Word8 -> Int -> IO ()
index 9a319fe..0ef0cea 100644 (file)
@@ -21,7 +21,6 @@ module GHC.IO.Handle.FD (
  ) where
 
 import GHC.Base
-import GHC.Real
 import GHC.Show
 import Data.Maybe
 -- import Control.Monad
@@ -240,7 +239,7 @@ fdToHandle' fdint mb_type is_socket filepath iomode binary = do
                         Just RegularFile -> Nothing
                           -- no stat required for streams etc.:
                         Just other       -> Just (other,0,0)
-  (fd,fd_type) <- FD.mkFD (fromIntegral fdint) iomode mb_stat
+  (fd,fd_type) <- FD.mkFD fdint iomode mb_stat
                        is_socket
                        is_socket
   mkHandleFromFD fd fd_type filepath iomode is_socket
@@ -255,8 +254,8 @@ fdToHandle' fdint mb_type is_socket filepath iomode binary = do
 -- translation instead.
 fdToHandle :: Posix.FD -> IO Handle
 fdToHandle fdint = do
-   iomode <- Posix.fdGetMode (fromIntegral fdint)
-   (fd,fd_type) <- FD.mkFD (fromIntegral fdint) iomode Nothing
+   iomode <- Posix.fdGetMode fdint
+   (fd,fd_type) <- FD.mkFD fdint iomode Nothing
             False{-is_socket-} 
               -- NB. the is_socket flag is False, meaning that:
               --  on Windows we're guessing this is not a socket (XXX)
index cf2541f..e37585c 100644 (file)
@@ -642,7 +642,7 @@ commitBuffer' raw sz@(I# _) count@(I# _) flush release
                 -- just copy the data in and update bufR.
             then do withRawBuffer raw     $ \praw ->
                       copyToRawBuffer old_raw (w*charSize)
-                                      praw (fromIntegral (count*charSize))
+                                      praw (count*charSize)
                     writeIORef ref old_buf{ bufR = w + count }
                     return (emptyBuffer raw sz WriteBuffer)
 
@@ -761,7 +761,7 @@ bufWrite h_@Handle__{..} ptr count can_block =
         -- There's enough room in the buffer:
         -- just copy the data in and update bufR.
         then do debugIO ("hPutBuf: copying to buffer, w=" ++ show w)
-                copyToRawBuffer old_raw w ptr (fromIntegral count)
+                copyToRawBuffer old_raw w ptr count
                 writeIORef haByteBuffer old_buf{ bufR = w + count }
                 return count
 
@@ -836,7 +836,7 @@ bufReadNonEmpty h_@Handle__{..}
                 return (so_far + count)
            else do
   
-        copyFromRawBuffer ptr raw (fromIntegral r) (fromIntegral avail)
+        copyFromRawBuffer ptr raw r avail
         let buf' = buf{ bufR=0, bufL=0 }
         writeIORef haByteBuffer buf'
         let remaining = count - avail
@@ -863,7 +863,7 @@ bufReadEmpty h_@Handle__{..}
   loop :: FD -> Int -> Int -> IO Int
   loop fd off bytes | bytes <= 0 = return (so_far + off)
   loop fd off bytes = do
-    r <- RawIO.read (fd::FD) (ptr `plusPtr` off) (fromIntegral bytes)
+    r <- RawIO.read (fd::FD) (ptr `plusPtr` off) bytes
     if r == 0
         then return (so_far + off)
         else loop fd (off + r) (bytes - r)
@@ -987,7 +987,7 @@ bufReadNBNonEmpty h_@Handle__{..}
                 return (so_far + count)
            else do
 
-        copyFromRawBuffer ptr raw (fromIntegral r) (fromIntegral avail)
+        copyFromRawBuffer ptr raw r avail
         let buf' = buf{ bufR=0, bufL=0 }
         writeIORef haByteBuffer buf'
         let remaining = count - avail
index 5304d83..c12fcea 100644 (file)
@@ -244,7 +244,6 @@ import System.Posix.Types
 
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
-import GHC.Real
 import GHC.IO hiding ( onException )
 import GHC.IO.IOMode
 import GHC.IO.Handle.FD
@@ -575,7 +574,7 @@ openTempFile' loc tmp_dir template binary mode = do
            else ioError (errnoToIOError loc errno Nothing (Just tmp_dir))
        else do
 
-         (fD,fd_type) <- FD.mkFD (fromIntegral fd) ReadWriteMode Nothing{-no stat-}
+         (fD,fd_type) <- FD.mkFD fd ReadWriteMode Nothing{-no stat-}
                               False{-is_socket-} 
                               True{-is_nonblock-}