Username: 
Password: 
Restrict session to IP 

A branchless php autoloader

Global Rank: 227
Totalscore: 94364
Posts: 1680
Thanks: 1358
UpVotes: 920
Registered: 16y 288d




Last Seen: 3d 11h
The User is Offline
A branchless php autoloader
Google/translate0Thank You!0Good Post!0Bad Post! link
I did it.
I finally came up with a branchless PHP autoloader.^^

GeSHi`ed php code
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
 
/**
 * The infamous 5 line phpgdo autoloader... was cancelled.
 * I present now: the branchless autoloader! :)
 *  * Generally both loaders work like this:
 * 1. Check if classname starts with `GDO\`
 * 2. Turn GDO\Module\Classname into a /fullpath.php (a tad faster on windows because a non required str_replace)
 * 3. Include the fullpath
 * 4. Increase performance counter, which is removed in production. * 
 * @author gizmore
 */
spl_autoload_register(function(string $name) : void
{        $call = [
                function() { }, # ignore
                function($name){ # include
                        $name = str_replace('\\', '/', $name); #PP#linux (only on linux) :)
                        include(GDO_PATH . $name . '.php'); # the worlds fastest autoloader.                        global $GDT_LOADED; # #PP#delete# performance metrics (only in dev)
                        $GDT_LOADED++;      # #PP#delete#
                },
        ];
        # Worlds first BRANCHLESS PHP Autoloader!         $call[((((ord($name[0]) << 8) |
                ord($name[3])) ^ 0xB8A3) + 1) >> 16]($name);
        
        # The original autoloader seems faster ;)
//      if ($name[0] === 'G' && $name[3] === '\\') # 1 line for an "if"//      {   # 2 lines for path + include
//              $name = str_replace('\\', '/', $name); #PP#linux (only on linux) :)
//              include(GDO_PATH . $name . '.php'); # the worlds fastest autoloader.
//              global $GDT_LOADED; # #PP#delete#
//              $GDT_LOADED++;      # #PP#delete#//      }
});
 
The geeks shall inherit the properties and methods of object earth.
Global Rank: 227
Totalscore: 94364
Posts: 1680
Thanks: 1358
UpVotes: 920
Registered: 16y 288d




Last Seen: 3d 11h
The User is Offline
RE: A branchless php autoloader
Google/translate0Thank You!0Good Post!0Bad Post! link
I am working a bit on a C90 Implementation of the algorithm that (might) feature:

- Branchless
- Unrolled a bit (playing with ASM and C =)
- memcmp (on it)
- strcmp (same as mem?)
- strcasecmp (just a little known trick for case-i?)


Later:

- Optional Constant Time (should be easy)

The project, codenamed "MeChelle", is online on GitHub under the path gizmore/MeChelleCompare
A test driven working implementation for a single 8/64bit uint compare is avaiable in test.c.

We will record and release a @Codinggeex video about this, and how to develop C with EclipseCDT very soon.

PS: Special greetz go to my trainee Krypt0, for having to watch "CGX#7: OOP (PHP)", supervised at work, as soon as it is released and rendered. Smile

Greetingz
- Giz
The geeks shall inherit the properties and methods of object earth.
tunelko, quangntenemy, TheHiveMind, Z, balicocat, Ge0, samuraiblanco, arraez, jcquinterov, hophuocthinh, alfamen2, burhanudinn123, Ben_Dover, stephanduran89, braddie0, SwolloW, dangarbri, csuquvq have subscribed to this thread and receive emails on new posts.
1 people are watching the thread at the moment.
This thread has been viewed 3494 times.