develooper Front page | perl.perl5.porters | Postings from February 2008

[patch] optimize OP_IS_(FILETEST|SOCKET) macros

Thread Next
Jim Cromie
February 9, 2008 06:57
[patch] optimize OP_IS_(FILETEST|SOCKET) macros
Message ID:

attached patch to generates faster/smaller versions
of 2 macros written to opcode.h


/* the OP_IS_(SOCKET|FILETEST) macros are optimized to a simple range
    check because all the member OPs are contiguous in
    <DATA> table. verifies the range contiguity.  */

#define OP_IS_SOCKET(op)        \
        ((op) >= OP_SEND && (op) <= OP_GETPEERNAME)

#define OP_IS_FILETEST(op)      \
        ((op) >= OP_FTRREAD && (op) <= OP_FTBINARY)

This optimized form is generated automatically when
the set of OPs have consecutive opnumbers, otherwize
the traditional form is generated.

I moved send & recv ops down in <DATA>
so that theyre contiguous with the others.
the OP_FT* ops were already consecutive.

Also, 1 unrelated touch to change enum opcode syntax
to explicitly number the enum symbols.

typedef enum opcode {
        OP_NULL          = 0,
        OP_STUB          = 1,
        OP_SCALAR        = 2,
        OP_PUSHMARK      = 3,
        OP_WANTARRAY     = 4,

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About