Skip to content

Commit

Permalink
Merge pull request #1220 from sjinks/memory
Browse files Browse the repository at this point in the history
PHALCON_INIT_NVAR(_PNULL) optimization
  • Loading branch information
Phalcon committed Sep 12, 2013
2 parents 67dd2b2 + ca8348d commit 5eebbe6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 68 deletions.
56 changes: 0 additions & 56 deletions ext/kernel/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,62 +48,6 @@
* Not all methods must grown/restore the phalcon_memory_entry.
*/

/**
* Initializes/Reinitializes a variable
*/
inline void phalcon_init_nvar(zval **var TSRMLS_DC) {
if (*var) {
if (Z_REFCOUNT_PP(var) > 1) {
Z_DELREF_PP(var);
ALLOC_ZVAL(*var);
Z_SET_REFCOUNT_PP(var, 1);
Z_UNSET_ISREF_PP(var);
} else {
zval_ptr_dtor(var);
PHALCON_ALLOC_ZVAL(*var);
}
} else {
phalcon_memory_alloc(var TSRMLS_CC);
}
}

/**
* Copy/Write variables caring of reference counting
*/
inline void phalcon_cpy_wrt(zval **dest, zval *var TSRMLS_DC) {

if (*dest) {
if (Z_REFCOUNT_PP(dest) > 0) {
zval_ptr_dtor(dest);
}
} else {
phalcon_memory_observe(dest TSRMLS_CC);
}

Z_ADDREF_P(var);
*dest = var;
}

/**
* Copy/Write variables caring of reference counting also duplicating the origin ctor
*/
inline void phalcon_cpy_wrt_ctor(zval **dest, zval *var TSRMLS_DC) {

if (*dest) {
if (Z_REFCOUNT_PP(dest) > 0) {
zval_ptr_dtor(dest);
}
} else {
phalcon_memory_observe(dest TSRMLS_CC);
}

Z_ADDREF_P(var);
*dest = var;
zval_copy_ctor(*dest);
Z_SET_REFCOUNT_PP(dest, 1);
Z_UNSET_ISREF_PP(dest);
}

static phalcon_memory_entry* phalcon_memory_grow_stack_common(zend_phalcon_globals *phalcon_globals_ptr)
{
assert(phalcon_globals_ptr->start_memory != NULL);
Expand Down
15 changes: 3 additions & 12 deletions ext/kernel/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
+------------------------------------------------------------------------+
*/

/* Variable Tracking */
extern void phalcon_init_nvar(zval **var TSRMLS_DC);
extern void phalcon_cpy_wrt(zval **dest, zval *var TSRMLS_DC);
extern void phalcon_cpy_wrt_ctor(zval **dest, zval *var TSRMLS_DC);

/* Memory Frames */
#ifndef PHALCON_RELEASE
void PHALCON_FASTCALL phalcon_memory_grow_stack(const char *func TSRMLS_DC);
Expand Down Expand Up @@ -73,8 +68,8 @@ extern void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);
Z_UNSET_ISREF_P(z); \
ZVAL_NULL(z); \
} else {\
zval_ptr_dtor(&z); \
PHALCON_ALLOC_ZVAL(z); \
zval_dtor(z); \
ZVAL_NULL(z); \
} \
} else { \
phalcon_memory_alloc(&z TSRMLS_CC); \
Expand All @@ -90,12 +85,8 @@ extern void PHALCON_FASTCALL phalcon_copy_ctor(zval *destiny, zval *origin);
ALLOC_ZVAL(z); \
Z_SET_REFCOUNT_P(z, 1); \
Z_UNSET_ISREF_P(z); \
ZVAL_NULL(z); \
} else {\
ZVAL_NULL(z); \
zval_ptr_dtor(&z); \
PHALCON_ALLOC_ZVAL(z); \
} \
ZVAL_NULL(z); \
} else { \
phalcon_memory_alloc_pnull(&z TSRMLS_CC); \
}
Expand Down

0 comments on commit 5eebbe6

Please sign in to comment.