]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20268 Significant performance improvement of generate_id()
authormudrd8mz <mudrd8mz>
Fri, 11 Sep 2009 19:54:11 +0000 (19:54 +0000)
committermudrd8mz <mudrd8mz>
Fri, 11 Sep 2009 19:54:11 +0000 (19:54 +0000)
Using the PHP's built-in generator instead of the current
implementation. See the issue description more details.

lib/outputcomponents.php

index aad58be8060150a9f4b8c424434a9768d5dd0e62..4cd7d01fabde9bbeb548cf53fcb2dd505c669119 100644 (file)
@@ -61,11 +61,6 @@ class moodle_html_component {
      * @var array $actions
      */
     protected $actions = array();
-    /**
-     * This array of generated ids is kept static to avoid id collisions
-     * @var array $generated_ids
-     */
-    public static $generated_ids = array();
 
     /**
      * Ensure some class names are an array.
@@ -173,12 +168,7 @@ class moodle_html_component {
      * Internal method for generating a unique ID for the purpose of event handlers.
      */
     protected function generate_id() {
-        // Generate an id that is not already used.
-        do {
-            $newid = get_class($this) . '-' . substr(sha1(microtime() * rand(0, 500)), 0, 6);
-        } while (in_array($this->id, moodle_html_component::$generated_ids));
-        $this->id = $newid;
-        moodle_html_component::$generated_ids[] = $newid;
+        $this->id = uniqid(get_class($this));
     }
 
     /**