Req #81561 [Opn->Csd]: Optimize `count` calls in conditions

From: Date: Thu, 28 Oct 2021 13:32:06 +0000
Subject: Req #81561 [Opn->Csd]: Optimize `count` calls in conditions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237416@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81561&edit=1 ID: 81561 Updated by: cmb@php.net Reported by: lars at moelleken dot org Summary: Optimize count calls in conditions -Status: Open +Status: Closed Type: Feature/Change Request Package: *General Issues PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: count() is O(1) since the number of elements is stored in the HashTable (basically the same for strings wrt. strlen()). So it is already optimized. Previous Comments: ------------------------------------------------------------------------ [2021-10-28 12:48:49] lars at moelleken dot org Description: ------------ While optimising (reducing) some count calls in phpstan-src, I thought: "Why do php count the full array in simpel conditions? Or is it already optimized?" Example: if (count($x) === 1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81561&edit=1

« previous php.bugs (#237416) next »