Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.438
diff -u -p -r1.438 configure.in
--- configure.in	9 Mar 2005 19:38:42 -0000	1.438
+++ configure.in	10 Mar 2005 17:47:19 -0000
@@ -808,7 +808,7 @@ fi
 AC_MSG_RESULT(unsigned $glib_size_type)
 
 # Check for some functions
-AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf setenv unsetenv getc_unlocked readlink symlink)
+AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf setenv unsetenv getc_unlocked readlink symlink mmap)
 
 AC_FUNC_VSNPRINTF_C99
 AC_FUNC_PRINTF_UNIX98
Index: glib/gscanner.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gscanner.c,v
retrieving revision 1.51
diff -u -p -r1.51 gscanner.c
--- glib/gscanner.c	16 Sep 2004 06:05:53 -0000	1.51
+++ glib/gscanner.c	10 Mar 2005 17:47:19 -0000
@@ -42,12 +42,19 @@
 #include	<unistd.h>
 #endif
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
 #include        "galias.h"
 #include	"glib.h"
 #include	"gprintfint.h"
 
 #ifdef G_OS_WIN32
-#include	<io.h>		/* For _read() */
+#include	<io.h>		/* for _read()         */
+#include	<windows.h>	/* for MapViewOfFile() */
 #endif
 
 /* --- defines --- */
@@ -121,6 +128,8 @@ static GScannerConfig g_scanner_config_t
 
 
 /* --- prototypes --- */
+static gboolean g_scanner_mmap            (GScanner     *scanner,
+                                           gint          input_fd);
 static inline
 GScannerKey*	g_scanner_lookup_internal (GScanner	*scanner,
 					   guint	 scope_id,
@@ -281,7 +290,20 @@ g_scanner_destroy (GScanner	*scanner)
   g_scanner_free_value (&scanner->token, &scanner->value);
   g_scanner_free_value (&scanner->next_token, &scanner->next_value);
   g_free (scanner->config);
-  g_free (scanner->buffer);
+
+  if (scanner->input_fd == -2)
+    {
+#ifdef HAVE_MMAP
+      munmap (scanner->buffer, scanner->text_end - scanner->buffer);
+#elif (defined G_OS_WIN32)
+      UnmapViewOfFile (scanner->buffer);
+#endif
+    }
+  else
+    {
+      g_free (scanner->buffer);
+    }
+
   g_free (scanner);
 }
 
@@ -662,12 +684,16 @@ g_scanner_input_file (GScanner *scanner,
   scanner->position = 0;
   scanner->next_token = G_TOKEN_NONE;
 
-  scanner->input_fd = input_fd;
-  scanner->text = NULL;
-  scanner->text_end = NULL;
+  if (! g_scanner_mmap (scanner, input_fd))
+    {
+      scanner->input_fd = input_fd;
+
+      scanner->text = NULL;
+      scanner->text_end = NULL;
 
-  if (!scanner->buffer)
-    scanner->buffer = g_new (gchar, READ_BUFFER_SIZE + 1);
+      if (!scanner->buffer)
+        scanner->buffer = g_new (gchar, READ_BUFFER_SIZE + 1);
+    }
 }
 
 void
@@ -699,6 +725,43 @@ g_scanner_input_text (GScanner	  *scanne
       g_free (scanner->buffer);
       scanner->buffer = NULL;
     }
+}
+
+static gboolean
+g_scanner_mmap (GScanner *scanner,
+                gint      input_fd)
+{
+#if defined(HAVE_MMAP) || defined(G_OS_WIN32)
+  struct stat st;
+
+  if (fstat (input_fd, &st) != -1 && S_ISREG (st.st_mode))
+    {
+      gpointer  map;
+
+#ifdef G_OS_WIN32
+      HANDLE  handle = CreateFileMapping ((HANDLE) _get_osfhandle (input_fd),
+                                          NULL, PAGE_READONLY, 0, 0, NULL);
+      map = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0);
+      CloseHandle (handle);
+#else
+      map = mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, input_fd, 0);
+#endif
+
+      if (map)
+        {
+          if (scanner->input_fd != -2 && scanner->buffer)
+            g_free (scanner->buffer);
+
+          scanner->input_fd = -2;
+          scanner->buffer = map;
+          scanner->text = scanner->buffer;
+          scanner->text_end = scanner->text + st.st_size;
+
+          return TRUE;
+        }
+    }
+#endif
+  return FALSE;
 }
 
 static guchar
