Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster version of Phalcon\DI using object handlers #1473

Merged
merged 6 commits into from Oct 30, 2013
Merged

Faster version of Phalcon\DI using object handlers #1473

merged 6 commits into from Oct 30, 2013

Conversation

ghost
Copy link

@ghost ghost commented Oct 29, 2013

No description provided.

@dreamsxin
Copy link
Contributor

+1

@phalcon
Copy link
Collaborator

phalcon commented Oct 30, 2013

I'm completely sure that this would be faster than the current DI, but it would be hard to produce similar code in Zephir

phalcon pushed a commit that referenced this pull request Oct 30, 2013
Faster version of Phalcon\DI using object handlers
@phalcon phalcon merged commit c4351e6 into phalcon:1.3.0 Oct 30, 2013
@ghost
Copy link
Author

ghost commented Oct 30, 2013

We can try. Object handlers are actually not that difficult.

Just take a look at this gist: https://gist.github.com/sjinks/5954372

I think we can start with basic implementation of __get(), __set(), __unset(), __isset(), offsetGet(), offsetSet(), offsetUnset(), offsetExists() via object handlers. This won't be as fast as the current code that uses object handlers, but still will be several times faster than the code that does not use object handlers.

Object handlers will look like this:

static void phalcon_di_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
{
    if (Z_OBJCE_P(object) != phalcon_di_ce) {
        /* Honor inheritance */
        zend_get_std_object_handlers()->write_dimension(object, offset, value TSRMLS_CC);
        return;
    }

    /* Here goes the code from the original offsetSet() */

    /* If offset and value have to be cast, we should do that here — the original parameters should not be changed */
    if (UNEXPECTED(Z_TYPE_P(offset) != IS_STRING)) {
        ZVAL_ZVAL(&tmp, offset, 1, 0);
        convert_to_string(&tmp);
        offset = &tmp;
    }

    /* Cleanup */
    if (UNEXPECTED(offset == &tmp)) {
        zval_dtor(&tmp);
    }
}

Object handlers are set up in the constructor (https://gist.github.com/sjinks/5954372#file-test-c-L27) and during the class registration (https://gist.github.com/sjinks/5954372#file-test-c-L68)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants