cvs: php-gtk(SO_BUILD_SYSTEM_BRANCH) /generator scheme.php

From: Date: Sun, 18 Nov 2001 01:27:22 +0000
Subject: cvs: php-gtk(SO_BUILD_SYSTEM_BRANCH) /generator scheme.php
Groups: php.gtk.cvs 
Request: Send a blank email to php-gtk-cvs+get-313@lists.php.net to get a copy of this message
andrei Sat Nov 17 20:27:22 2001 EDT Modified files: (Branch: SO_BUILD_SYSTEM_BRANCH) /php-gtk/generator scheme.php Log: Implemented caching of parsed definitions to save time when developing. Each parsed .defs file will result in a corresponding .defs.cache file in the same directory and the cache file will be used to load definitions unless .defs file changes. Index: php-gtk/generator/scheme.php diff -u php-gtk/generator/scheme.php:1.8 php-gtk/generator/scheme.php:1.8.2.1 --- php-gtk/generator/scheme.php:1.8 Tue Jul 31 01:27:01 2001 +++ php-gtk/generator/scheme.php Sat Nov 17 20:27:22 2001 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: scheme.php,v 1.8 2001/07/31 05:27:01 andrei Exp $ */ +/* $Id: scheme.php,v 1.8.2.1 2001/11/18 01:27:22 andrei Exp $ */ require "definitions.php"; @@ -66,6 +66,7 @@ class Defs_Parser { var $parse_tree = null; + var $parse_cache = null; var $file_path = null; var $file_name = null; var $objects = array(); // objects @@ -76,15 +77,11 @@ var $structs = array(); // structures var $c_name = array(); // C names of entities - function Defs_Parser($arg) { switch (gettype($arg)) { case 'string': - error_log("Parsing file \"$arg\"."); - $this->file_name = $arg; - $this->file_path = dirname($this->file_name); - $this->parse_tree = parse(fopen($arg, 'r')); + $this->_parse_or_load($arg); break; case 'array': @@ -97,12 +94,40 @@ } } + function _parse_or_load($defs_file) + { + $cache_file = $defs_file.'.cache'; + if (is_file($cache_file) && + filemtime($cache_file) > filemtime($defs_file)) { + error_log("Loading cache \"$cache_file\""); + $fp = fopen($cache_file, 'r'); + $this->parse_cache = fread($fp, filesize($cache_file)); + fclose($fp); + } else { + error_log("Parsing file \"$defs_file\"."); + $this->file_name = basename($defs_file); + $this->file_path = dirname($defs_file); + $this->parse_tree = parse(fopen($defs_file, 'r')); + } + } + function start_parsing($tree = NULL) { - if (!isset($tree)) - $tree = $this->parse_tree; - foreach ($tree as $node) - $this->handle($node); + if (isset($this->parse_cache)) { + $this = unserialize($this->parse_cache); + } else { + if (!isset($tree)) + $tree = $this->parse_tree; + foreach ($tree as $node) + $this->handle($node); + + if (is_writeable($this->file_path)) { + $cache_file = $this->file_path . '/' . $this->file_name . '.cache'; + $fp = fopen($cache_file, 'w'); + fwrite($fp, serialize($this)); + fclose($fp); + } + } } function merge($parser)

« previous php.gtk.cvs (#313) next »