Skip to content

Commit 7b2c3c1

Browse files
authored
Cleanup redundant lookups in phar_object.c (#10150)
1 parent c46a0ce commit 7b2c3c1

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

ext/phar/phar_object.c

+13-17
Original file line numberDiff line numberDiff line change
@@ -2606,16 +2606,14 @@ PHP_METHOD(Phar, delete)
26062606
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
26072607
RETURN_THROWS();
26082608
}
2609-
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
2610-
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
2611-
if (entry->is_deleted) {
2612-
/* entry is deleted, but has not been flushed to disk yet */
2613-
RETURN_TRUE;
2614-
} else {
2615-
entry->is_deleted = 1;
2616-
entry->is_modified = 1;
2617-
phar_obj->archive->is_modified = 1;
2618-
}
2609+
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
2610+
if (entry->is_deleted) {
2611+
/* entry is deleted, but has not been flushed to disk yet */
2612+
RETURN_TRUE;
2613+
} else {
2614+
entry->is_deleted = 1;
2615+
entry->is_modified = 1;
2616+
phar_obj->archive->is_modified = 1;
26192617
}
26202618
} else {
26212619
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s does not exist and cannot be deleted", fname);
@@ -3420,18 +3418,16 @@ PHP_METHOD(Phar, copy)
34203418
RETURN_THROWS();
34213419
}
34223420

3423-
if (!zend_hash_str_exists(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len) || NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len)) || oldentry->is_deleted) {
3421+
if (NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len)) || oldentry->is_deleted) {
34243422
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
34253423
"file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->archive->fname);
34263424
RETURN_THROWS();
34273425
}
34283426

3429-
if (zend_hash_str_exists(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) {
3430-
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) || !temp->is_deleted) {
3431-
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
3432-
"file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname);
3433-
RETURN_THROWS();
3434-
}
3427+
if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) && !temp->is_deleted) {
3428+
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
3429+
"file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname);
3430+
RETURN_THROWS();
34353431
}
34363432

34373433
tmp_len = newfile_len;

0 commit comments

Comments
 (0)