Skip to content

[JsonEncoder] Add native lazyghost support #59177

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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Dec 11, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT
  • Add support for native lazy ghost if available.
  • Improve var exporter lazy ghost usage, as it's not possible anymore to initialize a single property and letting the rest uninitialized.

The object part of a stream generated decoder changed from:

$data = \Symfony\Component\JsonEncoder\Decode\Splitter::splitDict($stream, $offset, $length);
$properties = [];
foreach ($data as $k => $v) {
    match ($k) {
        'id' => $properties['id'] = static function () use ($stream, $v, $options, $denormalizers, $instantiator, &$providers) {
            return \Symfony\Component\JsonEncoder\Decode\NativeDecoder::decodeStream($stream, $v[0], $v[1]);
        },
        'name' => $properties['name'] = static function () use ($stream, $v, $options, $denormalizers, $instantiator, &$providers) {
            return \Symfony\Component\JsonEncoder\Decode\NativeDecoder::decodeStream($stream, $v[0], $v[1]);
        },
        default => null,
    };
}
return $instantiator->instantiate(\Symfony\Component\JsonEncoder\Tests\Fixtures\Model\ClassicDummy::class, $properties);

to:

$data = \Symfony\Component\JsonEncoder\Decode\Splitter::splitDict($stream, $offset, $length);
return $instantiator->instantiate(\Symfony\Component\JsonEncoder\Tests\Fixtures\Model\ClassicDummy::class, static function ($object) use ($stream, $data, $options, $denormalizers, $instantiator, &$providers) {
    foreach ($data as $k => $v) {
        match ($k) {
            'id' => $object->id = \Symfony\Component\JsonEncoder\Decode\NativeDecoder::decodeStream($stream, $v[0], $v[1]),
            'name' => $object->name = \Symfony\Component\JsonEncoder\Decode\NativeDecoder::decodeStream($stream, $v[0], $v[1]),
            default => null,
        };
    }
});

@mtarld mtarld force-pushed the feat/json-encoder-lazy branch from 5e9fca5 to ffccbc3 Compare December 11, 2024 16:06
@carsonbot carsonbot changed the title [JsonEncoder] Add native lazyghost support Add native lazyghost support Dec 18, 2024
@carsonbot carsonbot changed the title Add native lazyghost support [JsonEncoder] Add native lazyghost support Dec 18, 2024
@fabpot
Copy link
Member

fabpot commented Dec 18, 2024

Thank you @mtarld.

@fabpot fabpot merged commit 7d6b9ad into symfony:7.3 Dec 18, 2024
3 of 11 checks passed
@mtarld mtarld deleted the feat/json-encoder-lazy branch March 3, 2025 10:14
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants