Commit efaf5abcf8e18833e426a3718fe372ffa9249e57

Su Yu 2009-08-03T19:55:58

Don't call `ft_fseek' every time when executing `ft_fread'. * src/base/ftstream.c (FT_Stream_Seek), src/base/ftsystem.c (ft_ansi_stream_io): Implement it.

diff --git a/ChangeLog b/ChangeLog
index 6b11600..745be62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-03  suyu0925@gmail.com
+
+	Don't call `ft_fseek' every time when executing `ft_fread'.
+
+	* src/base/ftstream.c (FT_Stream_Seek), src/base/ftsystem.c
+	(ft_ansi_stream_io): Implement it.
+
 2009-07-31  suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
 
 	sfnt: Cast a charcode to 32-bit in cmap format 14 parser.
diff --git a/src/base/ftstream.c b/src/base/ftstream.c
index d2d1749..b638599 100644
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -60,8 +60,6 @@
     FT_Error  error = FT_Err_Ok;
 
 
-    stream->pos = pos;
-
     if ( stream->read )
     {
       if ( stream->read( stream, pos, 0, 0 ) )
@@ -83,6 +81,9 @@
       error = FT_Err_Invalid_Stream_Operation;
     }
 
+    if ( !error )
+      stream->pos = pos;
+
     return error;
   }
 
diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c
index 251e59b..4d06d6d 100644
--- a/src/base/ftsystem.c
+++ b/src/base/ftsystem.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    ANSI-specific FreeType low-level system interface (body).            */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2006, 2008 by                               */
+/*  Copyright 1996-2001, 2002, 2006, 2008, 2009 by                         */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -205,7 +205,8 @@
 
     file = STREAM_FILE( stream );
 
-    ft_fseek( file, offset, SEEK_SET );
+    if ( stream->pos != offset )
+      ft_fseek( file, offset, SEEK_SET );
 
     return (unsigned long)ft_fread( buffer, 1, count, file );
   }