source: svn/trunk/processor/var-helper.h @ 1558

Last change on this file since 1558 was 1558, checked in by Xuefer, 5 years ago

closes #342: object caching

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1#ifdef ZEND_ENGINE_2
2static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
3{
4    size_t next_index = xc_vector_size(&processor->objects);
5
6    if (!xc_vector_initialized(&processor->objects)) {
7        xc_vector_init(zend_object, &processor->objects, 0);
8        zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
9    }
10
11    if (_zend_hash_index_update_or_next_insert(&processor->handle_to_index, handle, (void *) &next_index, sizeof(next_index), NULL, HASH_ADD ZEND_FILE_LINE_CC) == SUCCESS) {
12        zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
13        xc_vector_push_back(&processor->objects, object);
14    }
15}
16/* }}} */
17static size_t xc_var_store_handle(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
18{
19    size_t *index;
20
21    if (zend_hash_index_find(&processor->handle_to_index, handle, (void **) &index) != SUCCESS) {
22        php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle not found in objects");
23        return (size_t) -1;
24    }
25
26    return *index;
27}
28/* }}} */
29static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
30{
31    zend_object_handle handle = processor->object_handles[index];
32    zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
33    return handle;
34}
35/* }}} */
36#endif
37static void xc_var_collect_class(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
38{
39    size_t next_index = xc_vector_size(&processor->class_names);
40
41    if (zend_hash_add(&processor->class_name_to_index, ce->name, ce->name_length, (void *) &next_index, sizeof(next_index), NULL) == SUCCESS) {
42        xc_constant_string_t class_name = { ce->name, ce->name_length };
43        xc_vector_push_back(&processor->class_names, &class_name);
44    }
45}
46/* }}} */
47/* on store */
48static size_t xc_var_ce_to_index(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
49{
50    size_t *index;
51
52    if (zend_hash_find(&processor->class_name_to_index, ce->name, ce->name_length, (void **) &index) != SUCCESS) {
53        php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: class name not found in class names");
54        return (size_t) -1;
55    }
56
57    return *index;
58}
59/* }}} */
60/* on restore */
61static zend_class_entry *xc_var_index_to_ec(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
62{
63    xc_constant_string_t *name = &processor->entry_var_src->class_names[index];
64    zend_class_entry *ce;
65
66    if (!(ce = xc_lookup_class(name->str, name->len+1 TSRMLS_CC))) {
67        ce = zend_standard_class_def;
68        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s not found when restroing variable", name->str);
69    }
70    return ce;
71}
72/* }}} */
Note: See TracBrowser for help on using the repository browser.