Changeset 271 for trunk/ext/php

Show
Ignore:
Timestamp:
08/09/2007 05:41:29 (16 months ago)
Author:
indeyets
Message:

using inline-mode for short-and-flat maps and sequences

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/phpext.c

    r268 r271  
    455455 
    456456                case IS_STRING: 
    457                         syck_emit_scalar(e, "str", scalar_none, 0, 0, 0, Z_STRVAL_P(data), Z_STRLEN_P(data)); 
     457                        syck_emit_scalar(e, "str", scalar_2quote, 0, 0, 0, Z_STRVAL_P(data), Z_STRLEN_P(data)); 
    458458                break; 
    459459 
     
    461461                { 
    462462                        HashTable *tbl = Z_ARRVAL_P(data); 
     463                        int flat_and_short = false; 
     464 
     465                        /* we try to detect if array is short and flat */ 
     466                        if (tbl->nNumOfElements <= 6) { 
     467                                flat_and_short = true; 
     468 
     469                                for (zend_hash_internal_pointer_reset(tbl); zend_hash_has_more_elements(tbl) == SUCCESS; zend_hash_move_forward(tbl)) { 
     470                                        zval **ppzval; 
     471 
     472                                        zend_hash_get_current_data(tbl, (void **)&ppzval); 
     473 
     474                                        if (Z_TYPE_P(*ppzval) == IS_ARRAY || Z_TYPE_P(*ppzval) == IS_OBJECT) { 
     475                                                flat_and_short = false; 
     476                                        } 
     477                                } 
     478                        } 
    463479 
    464480                        if (zend_hash_index_exists(tbl, 0)) { 
    465481                                /* indexed array */ 
    466                                 syck_emit_seq(e, "table", seq_none); 
     482                                if (flat_and_short) 
     483                                        syck_emit_seq(e, "table", seq_inline); 
     484                                else 
     485                                        syck_emit_seq(e, "table", seq_none); 
    467486 
    468487                                for (zend_hash_internal_pointer_reset(tbl); zend_hash_has_more_elements(tbl) == SUCCESS; zend_hash_move_forward(tbl)) { 
     
    479498                        } else { 
    480499                                /* associative array */ 
    481                                 syck_emit_map(e, "table", map_none); 
     500                                if (flat_and_short) 
     501                                        syck_emit_map(e, "table", map_inline); 
     502                                else 
     503                                        syck_emit_map(e, "table", map_none); 
    482504 
    483505                                for (zend_hash_internal_pointer_reset(tbl); zend_hash_has_more_elements(tbl) == SUCCESS; zend_hash_move_forward(tbl)) {