|
From: <da...@us...> - 2003-11-22 16:48:18
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv18481
Modified Files:
php_var.cpp php_var.hpp testfile.php
Log Message:
Optimized php_var greatly.
Index: php_var.cpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** php_var.cpp 21 Nov 2003 12:36:43 -0000 1.36
--- php_var.cpp 22 Nov 2003 16:48:10 -0000 1.37
***************
*** 26,45 ****
php_var::php_var(double i)
{
! container = doublestring(i);
type = PHP_FLOAT;
}
php_var::php_var(int i)
{
! container = intstring(i);
type = PHP_INT;
}
php_var::php_var(unsigned int i)
{
! container = intstring(i);
type = PHP_INT;
}
php_var::php_var(long i)
{
! container = intstring(i);
type = PHP_INT;
}
--- 26,45 ----
php_var::php_var(double i)
{
! float_container = i;
type = PHP_FLOAT;
}
php_var::php_var(int i)
{
! int_container = i;
type = PHP_INT;
}
php_var::php_var(unsigned int i)
{
! int_container = i;
type = PHP_INT;
}
php_var::php_var(long i)
{
! int_container = i;
type = PHP_INT;
}
***************
*** 48,51 ****
--- 48,53 ----
type = temp.type;
container = temp.container;
+ int_container = temp.int_container;
+ float_container = temp.float_container;
keys = temp.keys;
data = temp.data;
***************
*** 65,71 ****
{
if(b)
! container = "1";
else
! container = "0";
type = PHP_BOOL;
}
--- 67,73 ----
{
if(b)
! int_container = 1;
else
! int_container = 0;
type = PHP_BOOL;
}
***************
*** 79,84 ****
if(type.is_array || type.is_object || type.is_resource )
return (char *)type;
! else
! return container.c_str();
}
php_var::operator string()
--- 81,93 ----
if(type.is_array || type.is_object || type.is_resource )
return (char *)type;
! switch(type)
! {
! case PHP_INT:
! return intstring(getint());
! case PHP_FLOAT:
! return doublestring(getfloat());
! case PHP_STRING:
! return getstring().c_str();
! }
}
php_var::operator string()
***************
*** 86,95 ****
if(type.is_array || type.is_object || type.is_resource )
return string((char *)type);
! else
! return container;
}
php_var::operator bool()
{
! if( !type.is_bool || (type.is_bool && container.compare("1") == 0))
return true;
return false;
--- 95,111 ----
if(type.is_array || type.is_object || type.is_resource )
return string((char *)type);
! switch(type)
! {
! case PHP_INT:
! return intstring(getint());
! case PHP_FLOAT:
! return doublestring(getfloat());
! case PHP_STRING:
! return getstring();
! }
}
php_var::operator bool()
{
! if( !type.is_bool || (type.is_bool && int_container == 0))
return true;
return false;
***************
*** 97,117 ****
php_var::operator double()
{
! return atof(container.c_str());
}
php_var::operator float()
{
! return (float)atof(container.c_str());
}
php_var::operator int()
{
! return atoi(container.c_str());
}
php_var::operator unsigned int()
{
! return atoi(container.c_str());
}
php_var::operator long()
{
! return atol(container.c_str());
}
php_var &php_var::operator[](int subscript)
--- 113,133 ----
php_var::operator double()
{
! return getfloat();
}
php_var::operator float()
{
! return getfloat();
}
php_var::operator int()
{
! return getint();
}
php_var::operator unsigned int()
{
! return getint();
}
php_var::operator long()
{
! return getlong();
}
php_var &php_var::operator[](int subscript)
***************
*** 158,162 ****
bool php_var::operator<(int i)
{
! if(atol(container.c_str()) < i)
return true;
return false;
--- 174,178 ----
bool php_var::operator<(int i)
{
! if(getint() < i)
return true;
return false;
***************
*** 164,168 ****
bool php_var::operator>(int i)
{
! if(atol(container.c_str()) > i)
return true;
return false;
--- 180,184 ----
bool php_var::operator>(int i)
{
! if(getint() > i)
return true;
return false;
***************
*** 170,174 ****
bool php_var::operator<(php_var i)
{
! if(atol(container.c_str()) < atol(i.container.c_str()))
return true;
return false;
--- 186,190 ----
bool php_var::operator<(php_var i)
{
! if(getint() < i.getint())
return true;
return false;
***************
*** 176,180 ****
bool php_var::operator>(php_var i)
{
! if(atol(container.c_str()) > atol(i.container.c_str()))
return true;
return false;
--- 192,196 ----
bool php_var::operator>(php_var i)
{
! if(getint() > i.getint())
return true;
return false;
***************
*** 188,192 ****
bool php_var::operator!=(int i)
{
! if(atol(container.c_str()) == i)
return false;
return true;
--- 204,208 ----
bool php_var::operator!=(int i)
{
! if(getint() == i)
return false;
return true;
***************
*** 194,209 ****
bool php_var::operator!=(php_var var)
{
! if(!container.compare(var.container))
! return false;
! return true;
}
bool php_var::operator==(const char* cmp)
{
! if(container.compare(cmp) == 0)
! return true;
return false;
}
bool php_var::operator==(int i)
{
if(atol(container.c_str()) == i)
return true;
--- 210,267 ----
bool php_var::operator!=(php_var var)
{
! switch(type)
! {
! case PHP_INT:
! return var.getint() != getint();
! break;
! case PHP_FLOAT:
! return var.getfloat() != getfloat();
! break;
! case PHP_BOOL:
! return var.getbool() != getbool();
! break;
! case PHP_STRING:
! return !container.compare(var.getstring());
! break;
! }
! return false;
}
bool php_var::operator==(const char* cmp)
{
! switch(type)
! {
! case PHP_INT:
! return strcmp(cmp, intstring(getint()));
! break;
! case PHP_FLOAT:
! return strcmp(cmp, doublestring(getfloat()));
! break;
! case PHP_BOOL:
! return strcmp(cmp, intstring(getint()));
! break;
! case PHP_STRING:
! return container.compare(cmp);
! break;
! }
return false;
}
bool php_var::operator==(int i)
{
+ switch(type)
+ {
+ case PHP_INT:
+ return (i == getint());
+ break;
+ case PHP_FLOAT:
+ return (i == getfloat());
+ break;
+ case PHP_BOOL:
+ return (i == getbool());
+ break;
+ case PHP_STRING:
+ return container.compare(intstring(i));
+ break;
+ }
+ return false;
if(atol(container.c_str()) == i)
return true;
***************
*** 212,242 ****
bool php_var::operator==(php_var var)
{
! if(container.compare(var.container) == 0)
! return true;
return false;
}
int php_var::operator++(int i)
{
! int ret = atol(container.c_str());
! container = intstring(ret + 1);
return ret;
}
int php_var::operator++()
{
! int ret = atol(container.c_str()) + 1;
! container = intstring(ret);
! return ret;
}
int php_var::operator--(int i)
{
! int ret = atol(container.c_str());
! container = intstring(ret);
return ret;
}
int php_var::operator--()
{
! int ret = atol(container.c_str()) + 1;
! container = intstring(ret);
! return ret;
}
php_var &php_var::operator=(const php_var &temp)
--- 270,309 ----
bool php_var::operator==(php_var var)
{
! switch(type)
! {
! case PHP_INT:
! return (var.getint() == getint());
! break;
! case PHP_FLOAT:
! return (var.getfloat() == getfloat());
! break;
! case PHP_BOOL:
! return (var.getbool() == getbool());
! break;
! case PHP_STRING:
! return container.compare(var.getstring());
! break;
! }
return false;
}
int php_var::operator++(int i)
{
! int ret = getint();
! *this = ret + 1;
return ret;
}
int php_var::operator++()
{
! return (*this = getint() + 1);
}
int php_var::operator--(int i)
{
! int ret = getint();
! *this = ret - 1;
return ret;
}
int php_var::operator--()
{
! return (*this = getint() - 1);
}
php_var &php_var::operator=(const php_var &temp)
***************
*** 244,247 ****
--- 311,316 ----
type = temp.type;
container = temp.container;
+ int_container = temp.int_container;
+ float_container = temp.float_container;
keys = temp.keys;
data = temp.data;
***************
*** 251,255 ****
php_var &php_var::operator=(int i)
{
! container = intstring(i);
type = PHP_INT;
return *this;
--- 320,324 ----
php_var &php_var::operator=(int i)
{
! int_container = i;
type = PHP_INT;
return *this;
***************
*** 257,261 ****
php_var &php_var::operator=(unsigned int i)
{
! container = intstring(i);
type = PHP_INT;
return *this;
--- 326,330 ----
php_var &php_var::operator=(unsigned int i)
{
! int_container = i;
type = PHP_INT;
return *this;
***************
*** 263,267 ****
php_var &php_var::operator=(long i)
{
! container = intstring(i);
type = PHP_INT;
return *this;
--- 332,336 ----
php_var &php_var::operator=(long i)
{
! int_container = i;
type = PHP_INT;
return *this;
***************
*** 269,273 ****
php_var &php_var::operator=(double d)
{
! container = doublestring(d);
type = PHP_FLOAT;
return *this;
--- 338,342 ----
php_var &php_var::operator=(double d)
{
! float_container = d;
type = PHP_FLOAT;
return *this;
***************
*** 288,294 ****
{
if(b)
! container = "1";
else
! container = "0";
type = PHP_BOOL;
return *this;
--- 357,363 ----
{
if(b)
! int_container = 1;
else
! int_container = 0;
type = PHP_BOOL;
return *this;
***************
*** 296,342 ****
void php_var::operator+=(int inc)
{
! if(type.is_int)
! {
! container = intstring(atol(container.c_str()) + inc);
! }
}
! void php_var::operator+=(php_var str)
{
! if(str.type.is_int)
! {
! container = intstring(atol(container.c_str()) + atoi(str.container.c_str()));
! if(!type.is_int && !type.is_string)
! type = PHP_INT;
! }
! else
! {
! container += str.container;
! if(!type.is_string)
! type = PHP_STRING;
! }
}
void php_var::operator+=(string str)
{
! container += str;
}
void php_var::operator+=(const char* str)
{
! container += str;
}
void php_var::operator+=(char* str)
{
! container += str;
}
void php_var::operator-=(int dec)
{
! if(type.is_int)
! {
! container = intstring(atol(container.c_str()) - dec);
! }
}
! void php_var::operator-=(php_var i)
{
! if(type.is_int)
! container = doublestring(atof(container.c_str()) - atof(i.container.c_str()));
}
void php_var::to_array()
--- 365,519 ----
void php_var::operator+=(int inc)
{
! switch(type)
! {
! case PHP_INT:
! int_container = getint() + inc;
! break;
! case PHP_FLOAT:
! float_container = getfloat() + inc;
! break;
! case PHP_STRING:
! container += intstring(inc);
! break;
! }
}
! void php_var::operator+=(php_var inc)
{
! switch(type)
! {
! case PHP_INT:
! switch(inc.type)
! {
! case PHP_INT:
! int_container += inc.int_container;
! break;
! case PHP_FLOAT:
! int_container += (int) inc.float_container;
! break;
! case PHP_STRING:
! container = (string) intstring(int_container) + inc.container;
! break;
! }
! break;
! case PHP_FLOAT:
! switch(inc.type)
! {
! case PHP_INT:
! float_container += inc.int_container;
! break;
! case PHP_FLOAT:
! float_container += inc.float_container;
! break;
! case PHP_STRING:
! container = (string) doublestring(int_container) + inc.container;
! break;
! }
! break;
! case PHP_STRING:
! switch(inc.type)
! {
! case PHP_INT:
! container += intstring(inc.int_container);
! break;
! case PHP_FLOAT:
! container += doublestring(inc.float_container);
! break;
! case PHP_STRING:
! container += inc.container;
! break;
! }
! break;
! }
}
void php_var::operator+=(string str)
{
! switch(type)
! {
! case PHP_INT:
! container = (string) intstring(int_container) + str;
! break;
! case PHP_FLOAT:
! container = (string) doublestring(float_container) + str;
! break;
! case PHP_STRING:
! container += str;
! break;
! }
}
void php_var::operator+=(const char* str)
{
! switch(type)
! {
! case PHP_INT:
! container = (string) intstring(int_container) + str;
! break;
! case PHP_FLOAT:
! container = (string) doublestring(float_container) + str;
! break;
! case PHP_STRING:
! container += str;
! break;
! }
}
void php_var::operator+=(char* str)
{
! switch(type)
! {
! case PHP_INT:
! container = (string) intstring(int_container) + str;
! break;
! case PHP_FLOAT:
! container = (string) doublestring(float_container) + str;
! break;
! case PHP_STRING:
! container += str;
! break;
! }
}
void php_var::operator-=(int dec)
{
! switch(type)
! {
! case PHP_INT:
! int_container = getint() - dec;
! break;
! case PHP_FLOAT:
! float_container = getfloat() - dec;
! break;
! }
}
! void php_var::operator-=(php_var inc)
{
! switch(type)
! {
! case PHP_INT:
! switch(inc.type)
! {
! case PHP_INT:
! int_container -= inc.int_container;
! break;
! case PHP_FLOAT:
! int_container -= (int) inc.float_container;
! break;
! case PHP_STRING:
! container = (string) intstring(int_container) + inc.container;
! break;
! }
! break;
! case PHP_FLOAT:
! switch(inc.type)
! {
! case PHP_INT:
! float_container -= inc.int_container;
! break;
! case PHP_FLOAT:
! float_container -= inc.float_container;
! break;
! case PHP_STRING:
! container = (string) doublestring(int_container) + inc.container;
! break;
! }
! break;
! }
}
void php_var::to_array()
***************
*** 352,358 ****
{
if(var.type.is_array)
out << "Array";
! else
! out << var.container;
return out;
}
--- 529,550 ----
{
if(var.type.is_array)
+ {
out << "Array";
! return out;
! }
! php_var *php = (php_var *) &var;
! switch(php->type)
! {
! case PHP_BOOL:
! case PHP_INT:
! out << intstring(php->int_container);
! break;
! case PHP_FLOAT:
! out << doublestring(php->float_container);
! break;
! case PHP_STRING:
! out << php->container;
! break;
! }
return out;
}
***************
*** 377,379 ****
--- 569,660 ----
return (php_var)((long) l - (long) r);
}
+
+ int php_var::getint()
+ {
+ switch(type)
+ {
+ case PHP_INT:
+ return int_container;
+ break;
+ case PHP_FLOAT:
+ return (int) float_container;
+ break;
+ case PHP_BOOL:
+ return (int_container == 0) ? 0 : 1;
+ break;
+ case PHP_STRING:
+ return atoi(container.c_str());
+ default:
+ return 0;
+ break;
+ }
+ }
+ float php_var::getfloat()
+ {
+ switch(type)
+ {
+ case PHP_INT:
+ return (float) int_container;
+ break;
+ case PHP_FLOAT:
+ return float_container;
+ break;
+ case PHP_BOOL:
+ return (int_container == 0) ? 0 : 1;
+ break;
+ case PHP_STRING:
+ return atof(container.c_str());
+ default:
+ return 0;
+ break;
+ }
+ }
+ bool php_var::getbool()
+ {
+ if(getint() == 1)
+ return true;
+ return false;
+ }
+ long php_var::getlong()
+ {
+ switch(type)
+ {
+ case PHP_INT:
+ return int_container;
+ break;
+ case PHP_FLOAT:
+ return (long) float_container;
+ break;
+ case PHP_BOOL:
+ return (getbool()) ? 0 : 1;
+ break;
+ case PHP_STRING:
+ return atol(container.c_str());
+ default:
+ return 0;
+ break;
+ }
+ }
+ string php_var::getstring()
+ {
+ switch(type)
+ {
+ case PHP_INT:
+ return intstring(int_container);
+ break;
+ case PHP_FLOAT:
+ return doublestring(float_container);
+ break;
+ case PHP_BOOL:
+ return (getbool()) ? "0" : "1";
+ break;
+ case PHP_STRING:
+ return container;
+ break;
+ default:
+ return "";
+ break;
+ }
+ }
+
#define is_identical(var, varb) (((var) == (varb) && (var).type == (varb).type) ? (php_var)true : (php_var)false)
Index: php_var.hpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** php_var.hpp 21 Nov 2003 12:36:43 -0000 1.7
--- php_var.hpp 22 Nov 2003 16:48:10 -0000 1.8
***************
*** 72,86 ****
void operator+=(int inc);
! void operator+=(php_var str);
void operator+=(string str);
void operator+=(const char* str);
void operator+=(char* str);
void operator-=(int dec);
! void operator-=(php_var i);
friend ostream &operator<<( ostream &out, const php_var &var );
void to_array();
string container; // Contains value.
vector<php_var> keys;
vector<php_var> data;
--- 72,93 ----
void operator+=(int inc);
! void operator+=(php_var inc);
void operator+=(string str);
void operator+=(const char* str);
void operator+=(char* str);
void operator-=(int dec);
! void operator-=(php_var dec);
friend ostream &operator<<( ostream &out, const php_var &var );
void to_array();
+ int getint();
+ float getfloat();
+ bool getbool();
+ long getlong();
+ string getstring();
string container; // Contains value.
+ long int_container;
+ float float_container;
vector<php_var> keys;
vector<php_var> data;
Index: testfile.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/testfile.php,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** testfile.php 21 Nov 2003 12:36:43 -0000 1.51
--- testfile.php 22 Nov 2003 16:48:10 -0000 1.52
***************
*** 1,8 ****
<?php
! class foo
! {
! var $bar = 'bleh';
! }
! $moo = new foo();
! echo $moo->bar;
?>
--- 1,4 ----
<?php
! for($i = 0; $i < 500000; ++$i)
! echo $i, "\n";
?>
|