Simplified the access in `User::__get()`
authorAlexander Ebert <ebert@woltlab.com>
Fri, 18 Feb 2022 17:21:46 +0000 (18:21 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 18 Feb 2022 17:21:46 +0000 (18:21 +0100)
Called 500-1k times per request, this change reduces the time spent inside this method by about 40% on average.

wcfsetup/install/files/lib/data/user/User.class.php

index 8897bcd65f59e991da9183577f82508e267491a1..a1d6404cb218f72f8c33287578701ad2db822805 100644 (file)
@@ -303,11 +303,7 @@ final class User extends DatabaseObject implements IPopoverObject, IRouteControl
             return;
         }
 
-        if (!isset($this->data['userOption' . $optionID])) {
-            return;
-        }
-
-        return $this->data['userOption' . $optionID];
+        return $this->data['userOption' . $optionID] ?? null;
     }
 
     /**
@@ -344,11 +340,8 @@ final class User extends DatabaseObject implements IPopoverObject, IRouteControl
     public function __get($name)
     {
         $value = parent::__get($name);
-        if ($value === null) {
-            $value = $this->getUserOption($name);
-        }
 
-        return $value;
+        return $value ?? $this->getUserOption($name);
     }
 
     /**