[php-src] master: ext/phar: Avoid redundant manifest hash lookup in offsetUnset() (#22437)

Arshid via GitHub <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Arshid (arshidkv12)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-06-26T09:23:30+01:00

Commit: https://github.com/php/php-src/commit/c4b74d407334df05341adcc7b361ad0551f6fd6b
Raw diff: https://github.com/php/php-src/commit/c4b74d407334df05341adcc7b361ad0551f6fd6b.diff

ext/phar: Avoid redundant manifest hash lookup in offsetUnset() (#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.

Changed paths:
  M  ext/phar/phar_object.c


Diff:

diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index e2ba71c501e7..7eb8392e6c69 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -3741,33 +3741,32 @@ PHP_METHOD(Phar, offsetUnset)
 		RETURN_THROWS();
 	}
 
-	if (zend_hash_exists(&phar_obj->archive->manifest, file_name)) {
-		phar_entry_info *entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
-		if (entry) {
-			if (entry->is_deleted) {
-				/* entry is deleted, but has not been flushed to disk yet */
-				return;
-			}
+	phar_entry_info *entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
+	if (entry) {
+		if (entry->is_deleted) {
+			/* entry is deleted, but has not been flushed to disk yet */
+			return;
+		}
 
-			if (phar_obj->archive->is_persistent) {
-				if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
-					zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", ZSTR_VAL(phar_obj->archive->fname));
-					RETURN_THROWS();
-				}
-				/* re-populate entry after copy on write */
-				entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
+		if (phar_obj->archive->is_persistent) {
+			if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
+				zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", ZSTR_VAL(phar_obj->archive->fname));
+				RETURN_THROWS();
 			}
-			entry->is_modified = 0;
-			entry->is_deleted = 1;
-			/* we need to "flush" the stream to save the newly deleted file on disk */
-			phar_flush(phar_obj->archive, &error);
+			/* re-populate entry after copy on write */
+			entry = zend_hash_find_ptr(&phar_obj->archive->manifest, file_name);
+		}
+		entry->is_modified = 0;
+		entry->is_deleted = 1;
+		/* we need to "flush" the stream to save the newly deleted file on disk */
+		phar_flush(phar_obj->archive, &error);
 
-			if (error) {
-				zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
-				efree(error);
-			}
+		if (error) {
+			zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
+			efree(error);
 		}
 	}
+	
 }
 /* }}} */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.