inc2734 / unitone

34 stars 4 forks source link

ブロックの数が増えたり入れ子が深くなったりするとパフォーマンスが悪くなる #366

Closed inc2734 closed 1 week ago

inc2734 commented 2 weeks ago
const _asert = ( _value, _current, _default, expected ) => {
    const compactDefault = compacting( _default );
    const fullDefault = expand( compactDefault );
    const preNewGap = expand( _current );

    let newGap = {
        column: _value ||
            ( null == fullDefault?.column || _value === fullDefault?.column
                ? undefined
                : '' ),
        row: preNewGap?.row ?? fullDefault?.row,
    };

    // current が undefined で default が数値のときは row に default が入る
    // 分割値の場合、PHP 側で default.row は参照するけど、default は参照しないため
    if ( null == _current && isString( _default ) ) {
        newGap.row = _default;
    }

    // current.column が数値で current.row がなく、
    if ( null != _current?.column && null == _current?.row ) {
        if ( isString( _default?.row ) ) {
            // default.row が数値のときは row に default.row が入る
            newGap.row = _default?.row;
        } else if ( isString( _default ) ) {
            // default が数値のときは row に '' が入る
            newGap.row = '';
        }
    }

    newGap = compacting( newGap, _default );

    const assertion = cleanEmptyObject( newGap );

    return console.assert(
        JSON.stringify( assertion ) === JSON.stringify( expected ),
        {
            '1: _value': _value,
            '2: _current': _current,
            '3: _default': _default,
            '4: compactDefault': compactDefault,
            '5: fullDefault': fullDefault,
            '6: preNewGap': preNewGap,
            '7: newGap': newGap,
            '8: expected': expected,
            '9: assertion': assertion,
        }
    );
};

_asert( '', undefined, undefined, undefined );
_asert( '', undefined, '1', { column: '', row: '1' } );
_asert( '', undefined, '2', { column: '', row: '2' } );
_asert( '', undefined, { row: '1' }, undefined );
_asert( '', undefined, { column: '1' }, { column: '' } );
_asert( '', undefined, { column: '1', row: '1' }, { column: '' } );
_asert( '', undefined, { column: '2', row: '1' }, { column: '' } );
_asert( '', undefined, { column: '', row: '1' }, undefined );
_asert( '', undefined, { column: '1', row: '' }, '' );

_asert( '', '1', undefined, { row: '1' } );
_asert( '', '1', '1', { column: '', row: '1' } );
_asert( '', '1', '2', { column: '', row: '1' } );
_asert( '', '1', { row: '1' }, undefined );
_asert( '', '1', { column: '1' }, { column: '', row: '1' } );
_asert( '', '1', { column: '1', row: '1' }, { column: '' } );
_asert( '', '1', { column: '2', row: '1' }, { column: '' } );
_asert( '', '1', { column: '', row: '1' }, undefined );
_asert( '', '1', { column: '1', row: '' }, { column: '', row: '1' } );

_asert( '', { row: '1' }, undefined, { row: '1' } );
_asert( '', { row: '1' }, '1', { column: '', row: '1' } );
_asert( '', { row: '1' }, '2', { column: '', row: '1' } );
_asert( '', { row: '1' }, { row: '1' }, undefined );
_asert( '', { row: '1' }, { column: '1' }, { column: '', row: '1' } );
_asert( '', { row: '1' }, { column: '1', row: '1' }, { column: '' } );
_asert( '', { row: '1' }, { column: '2', row: '1' }, { column: '' } );
_asert( '', { row: '1' }, { column: '', row: '1' }, undefined );
_asert( '', { row: '1' }, { column: '1', row: '' }, { column: '', row: '1' } );

_asert( '', { column: '1' }, undefined, undefined );
_asert( '', { column: '1' }, '1', '' );
_asert( '', { column: '1' }, '2', '' );
_asert( '', { column: '1' }, { row: '1' }, undefined );
_asert( '', { column: '1' }, { column: '1' }, { column: '' } );
_asert( '', { column: '1' }, { column: '1', row: '1' }, { column: '' } );
_asert( '', { column: '1' }, { column: '2', row: '1' }, { column: '' } );
_asert( '', { column: '1' }, { column: '', row: '1' }, undefined );
_asert( '', { column: '1' }, { column: '1', row: '' }, '' );

_asert( '', { column: '1', row: '1' }, undefined, { row: '1' } );
_asert( '', { column: '1', row: '1' }, '1', { column: '', row: '1' } );
_asert( '', { column: '1', row: '1' }, '2', { column: '', row: '1' } );
_asert( '', { column: '1', row: '1' }, { row: '1' }, undefined );
_asert( '', { column: '1', row: '1' }, { column: '' }, { row: '1' } );
_asert( '', { column: '1', row: '1' }, { column: '1', row: '1' }, { column: '' } );
_asert( '', { column: '1', row: '1' }, { column: '2', row: '1' }, { column: '' } );
_asert( '', { column: '1', row: '1' }, { column: '', row: '1' }, undefined );
_asert( '', { column: '1', row: '1' }, { column: '1', row: '' }, { column: '', row: '1' } );

_asert( '1', undefined, undefined, { column: '1' } );
_asert( '1', undefined, '1', undefined );
_asert( '1', undefined, '2', { column: '1', row: '2' } );
_asert( '1', undefined, { row: '1' }, '1' );
_asert( '1', undefined, { column: '1' }, undefined );
_asert( '1', undefined, { column: '1', row: '1' }, undefined );
_asert( '1', undefined, { column: '2', row: '1' }, '1' );
_asert( '1', undefined, { column: '', row: '1' }, '1' );
_asert( '1', undefined, { column: '1', row: '' }, undefined );

_asert( '1', '1', undefined, '1' );
_asert( '1', '1', '1', undefined );
_asert( '1', '1', '2', '1' );
_asert( '1', '1', { row: '1' }, '1' );
_asert( '1', '1', { column: '1' }, '1' );
_asert( '1', '1', { column: '1', row: '1' }, undefined );
_asert( '1', '1', { column: '2', row: '1' }, '1' );
_asert( '1', '1', { column: '', row: '1' }, '1' );
_asert( '1', '1', { column: '1', row: '' }, '1' );

_asert( '1', { row: '1' }, undefined, '1' );
_asert( '1', { row: '1' }, '1', undefined );
_asert( '1', { row: '1' }, '2', '1' );
_asert( '1', { row: '1' }, { row: '1' }, '1' );
_asert( '1', { row: '1' }, { column: '1' }, '1' );
_asert( '1', { row: '1' }, { column: '1', row: '1' }, undefined );
_asert( '1', { row: '1' }, { column: '2', row: '1' }, '1' );
_asert( '1', { row: '1' }, { column: '', row: '1' }, '1' );
_asert( '1', { row: '1' }, { column: '1', row: '' }, '1' );

_asert( '1', { column: '1' }, undefined, { column: '1' } );
_asert( '1', { column: '1' }, '1', { column: '1', row: '' } );
_asert( '1', { column: '1' }, '2', { column: '1', row: '' } );
_asert( '1', { column: '1' }, { row: '1' }, '1' );
_asert( '1', { column: '1' }, { column: '1' }, undefined );
_asert( '1', { column: '1' }, { column: '1', row: '1' }, undefined );
_asert( '1', { column: '1' }, { column: '2', row: '1' }, '1' );
_asert( '1', { column: '1' }, { column: '', row: '1' }, '1' );
_asert( '1', { column: '1' }, { column: '1', row: '' }, undefined );

_asert( '1', { column: '1', row: '1' }, undefined, '1' );
_asert( '1', { column: '1', row: '1' }, '1', undefined );
_asert( '1', { column: '1', row: '1' }, '2', '1' );
_asert( '1', { column: '1', row: '1' }, { row: '1' }, '1' );
_asert( '1', { column: '1', row: '1' }, { column: '' }, '1' );
_asert( '1', { column: '1', row: '1' }, { column: '1', row: '1' }, undefined );
_asert( '1', { column: '1', row: '1' }, { column: '2', row: '1' }, '1' );
_asert( '1', { column: '1', row: '1' }, { column: '', row: '1' }, '1' );
_asert( '1', { column: '1', row: '1' }, { column: '1', row: '' }, '1' );