Permalink
Browse files

Substitute persistent constants by their values at compile time. (Matt)

  • Loading branch information...
Dmitry Stogov
Dmitry Stogov committed Jul 25, 2008
1 parent bb35ab4 commit ed2d3e4c7ede51ba6102afd50301ab3c06280d3a
Showing with 14 additions and 1 deletion.
  1. +1 −0 NEWS
  2. +10 −1 Zend/zend_compile.c
  3. +3 −0 Zend/zend_compile.h
View
1 NEWS
@@ -43,6 +43,7 @@ PHP NEWS
. Added ability to handle exceptions in destructors. (Marcus)
- Improved PHP runtime speed and memory usage:
+ . Substitute persistent constants by their values at compile time. (Matt)
. Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
. Removed direct executor recursion. (Dmitry)
. Use fastcall calling convention in executor on x86. (Dmitry)
View
@@ -3804,6 +3804,13 @@ static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */
if (c->flags & CONST_CT_SUBST) {
return c;
}
+ if ((c->flags & CONST_PERSISTENT) &&
+ !CG(current_namespace) &&
+ !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) &&
+ Z_TYPE(c->value) != IS_CONSTANT &&
+ Z_TYPE(c->value) != IS_CONSTANT_ARRAY) {
+ return c;
+ }
return NULL;
}
/* }}} */
@@ -5171,12 +5178,14 @@ void zend_do_use(znode *ns_name, znode *new_name, int is_global TSRMLS_DC) /* {{
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
{
zend_op *opline;
+ zend_constant *c;
if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
}
- if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) {
+ c = zend_get_ct_const(&name->u.constant TSRMLS_CC);
+ if (c && (c->flags & CONST_CT_SUBST)) {
zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant));
}
View
@@ -762,6 +762,9 @@ END_EXTERN_C()
/* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
#define ZEND_COMPILE_DELAYED_BINDING (1<<4)
+/* disable constant substitution at compile-time */
+#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION (1<<5)
+
/* The default value for CG(compiler_options) */
#define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY

0 comments on commit ed2d3e4

Please sign in to comment.