Skip to content

Commit c4b74d4

Browse files
authored
ext/phar: Avoid redundant manifest hash lookup in offsetUnset() (php#22437)
Replace `zend_hash_exists()` + `zend_hash_find_ptr()` with a single `zend_hash_find_ptr()` call and a `NULL` check, avoiding an unnecessary HashTable lookup.
1 parent 1cf6da6 commit c4b74d4

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

ext/phar/phar_object.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,33 +3741,32 @@ PHP_METHOD(Phar, offsetUnset)
37413741
RETURN_THROWS();
37423742
}
37433743

3744-
if (zend_hash_exists(&phar_obj->archive->manifest, file_name)) {
3745-
phar_entry_info *entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
3746-
if (entry) {
3747-
if (entry->is_deleted) {
3748-
/* entry is deleted, but has not been flushed to disk yet */
3749-
return;
3750-
}
3744+
phar_entry_info *entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
3745+
if (entry) {
3746+
if (entry->is_deleted) {
3747+
/* entry is deleted, but has not been flushed to disk yet */
3748+
return;
3749+
}
37513750

3752-
if (phar_obj->archive->is_persistent) {
3753-
if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
3754-
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", ZSTR_VAL(phar_obj->archive->fname));
3755-
RETURN_THROWS();
3756-
}
3757-
/* re-populate entry after copy on write */
3758-
entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
3751+
if (phar_obj->archive->is_persistent) {
3752+
if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
3753+
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", ZSTR_VAL(phar_obj->archive->fname));
3754+
RETURN_THROWS();
37593755
}
3760-
entry->is_modified = 0;
3761-
entry->is_deleted = 1;
3762-
/* we need to "flush" the stream to save the newly deleted file on disk */
3763-
phar_flush(phar_obj->archive, &error);
3756+
/* re-populate entry after copy on write */
3757+
entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
3758+
}
3759+
entry->is_modified = 0;
3760+
entry->is_deleted = 1;
3761+
/* we need to "flush" the stream to save the newly deleted file on disk */
3762+
phar_flush(phar_obj->archive, &error);
37643763

3765-
if (error) {
3766-
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
3767-
efree(error);
3768-
}
3764+
if (error) {
3765+
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
3766+
efree(error);
37693767
}
37703768
}
3769+
37713770
}
37723771
/* }}} */
37733772

0 commit comments

Comments
 (0)