[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

mjs mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:31:23 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit da18fd0beaa4bff172c6dd67b488c05697b72377
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Aug 15 12:02:07 2002 +0000

    	Phase 2 of fixnum optimization. Store any integral number that
    	will fit in two bits less than a long inside the ValueImp *
    	itself, thus avoiding the need to deal with the garbage collector
    	at all for these types. Such numbers comprised .5 million of the
    	1.7 million ValueImps created during the cvs-js-performance test,
    	so traffic through the garbage collector should be
    
    	20% improvement on cvs-js-performance. This may also show up on
    	cvs-base, but I did not compare and I am too lazy to make clean in
    	WebCore yet again.
    
    	This also significantly reduces memory footprint on
    	JavaScript-heavy pages. Size after going through
    	cvs-js-performance suite is now down from 22 MB to 17.5 MB.
    
            * JavaScriptCore.pbproj/project.pbxproj:
            * kjs/simple_number.h: Added. Some inline static methods for handling
    	simple numbers that are stored in the pointer.
            * kjs/ustring.h:
            * kjs/ustring.cpp:
            (UString::from): Added new overload for long.
            * kjs/value.cpp:
            (ValueImp::marked): Add special case for simple numbers.
            (ValueImp::setGcAllowed): Likewise.
    	(ValueImp::toInteger): Call dispatch version of
    	toUInt32(unsigned&), not the real method.
            (ValueImp::toInt32): Likewise.
            (ValueImp::toUInt32): Likewise.
            (ValueImp::toUInt16): Likewise.
            (ValueImp::dispatchType): Add special case for simple numbers.
            (ValueImp::dispatchToPrimitive): Likewise.
            (ValueImp::dispatchToBoolean): Likewise.
            (ValueImp::dispatchToNumber): Likewise.
            (ValueImp::dispatchToString): Likewise.
            (ValueImp::dispatchToObject): Likewise.
            (ValueImp::dispatchToUInt32): Likewise.
            (ValueImp::dispatchGetBase): Likewise.
            (ValueImp::dispatchGetPropertyName): Likewise.
            (ValueImp::dispatchPutValue): Likewise.
            (ValueImp::dispatchDeleteValue): Likewise.
            (Number::Number): Create a simple number instead of a full-blown
    	ValueImp when possible.
            (Number::value): Likewise.
            * kjs/value.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1825 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 2d66890..314fa40 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,52 @@
 2002-08-15  Maciej Stachowiak  <mjs at apple.com>
 
+	Phase 2 of fixnum optimization. Store any integral number that
+	will fit in two bits less than a long inside the ValueImp *
+	itself, thus avoiding the need to deal with the garbage collector
+	at all for these types. Such numbers comprised .5 million of the
+	1.7 million ValueImps created during the cvs-js-performance test,
+	so traffic through the garbage collector should be
+
+	20% improvement on cvs-js-performance. This may also show up on
+	cvs-base, but I did not compare and I am too lazy to make clean in
+	WebCore yet again. 
+
+	This also significantly reduces memory footprint on
+	JavaScript-heavy pages. Size after going through
+	cvs-js-performance suite is now 22MB to 17.5MB.
+	
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * kjs/simple_number.h: Added. Some inline static methods for handling
+	simple numbers that are stored in the pointer.
+        * kjs/ustring.h:
+        * kjs/ustring.cpp:
+        (UString::from): Added new overload for long.
+        * kjs/value.cpp:
+        (ValueImp::marked): Add special case for simple numbers.
+        (ValueImp::setGcAllowed): Likewise.
+	(ValueImp::toInteger): Call dispatch version of
+	toUInt32(unsigned&), not the real method.
+        (ValueImp::toInt32): Likewise.
+        (ValueImp::toUInt32): Likewise.
+        (ValueImp::toUInt16): Likewise.
+        (ValueImp::dispatchType): Add special case for simple numbers.
+        (ValueImp::dispatchToPrimitive): Likewise.
+        (ValueImp::dispatchToBoolean): Likewise.
+        (ValueImp::dispatchToNumber): Likewise.
+        (ValueImp::dispatchToString): Likewise.
+        (ValueImp::dispatchToObject): Likewise.
+        (ValueImp::dispatchToUInt32): Likewise.
+        (ValueImp::dispatchGetBase): Likewise.
+        (ValueImp::dispatchGetPropertyName): Likewise.
+        (ValueImp::dispatchPutValue): Likewise.
+        (ValueImp::dispatchDeleteValue): Likewise.
+        (Number::Number): Create a simple number instead of a full-blown
+	ValueImp when possible.
+        (Number::value): Likewise.
+        * kjs/value.h:
+
+2002-08-15  Maciej Stachowiak  <mjs at apple.com>
+
 	Phase one of the "fixnum" optimization (storing small enough
 	integers in the pointer). This just paves the way for the change
 	by making all the virtual functions of ValueImp private and adding
diff --git a/JavaScriptCore/ChangeLog-2002-12-03 b/JavaScriptCore/ChangeLog-2002-12-03
index 2d66890..314fa40 100644
--- a/JavaScriptCore/ChangeLog-2002-12-03
+++ b/JavaScriptCore/ChangeLog-2002-12-03
@@ -1,5 +1,52 @@
 2002-08-15  Maciej Stachowiak  <mjs at apple.com>
 
+	Phase 2 of fixnum optimization. Store any integral number that
+	will fit in two bits less than a long inside the ValueImp *
+	itself, thus avoiding the need to deal with the garbage collector
+	at all for these types. Such numbers comprised .5 million of the
+	1.7 million ValueImps created during the cvs-js-performance test,
+	so traffic through the garbage collector should be
+
+	20% improvement on cvs-js-performance. This may also show up on
+	cvs-base, but I did not compare and I am too lazy to make clean in
+	WebCore yet again. 
+
+	This also significantly reduces memory footprint on
+	JavaScript-heavy pages. Size after going through
+	cvs-js-performance suite is now 22MB to 17.5MB.
+	
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * kjs/simple_number.h: Added. Some inline static methods for handling
+	simple numbers that are stored in the pointer.
+        * kjs/ustring.h:
+        * kjs/ustring.cpp:
+        (UString::from): Added new overload for long.
+        * kjs/value.cpp:
+        (ValueImp::marked): Add special case for simple numbers.
+        (ValueImp::setGcAllowed): Likewise.
+	(ValueImp::toInteger): Call dispatch version of
+	toUInt32(unsigned&), not the real method.
+        (ValueImp::toInt32): Likewise.
+        (ValueImp::toUInt32): Likewise.
+        (ValueImp::toUInt16): Likewise.
+        (ValueImp::dispatchType): Add special case for simple numbers.
+        (ValueImp::dispatchToPrimitive): Likewise.
+        (ValueImp::dispatchToBoolean): Likewise.
+        (ValueImp::dispatchToNumber): Likewise.
+        (ValueImp::dispatchToString): Likewise.
+        (ValueImp::dispatchToObject): Likewise.
+        (ValueImp::dispatchToUInt32): Likewise.
+        (ValueImp::dispatchGetBase): Likewise.
+        (ValueImp::dispatchGetPropertyName): Likewise.
+        (ValueImp::dispatchPutValue): Likewise.
+        (ValueImp::dispatchDeleteValue): Likewise.
+        (Number::Number): Create a simple number instead of a full-blown
+	ValueImp when possible.
+        (Number::value): Likewise.
+        * kjs/value.h:
+
+2002-08-15  Maciej Stachowiak  <mjs at apple.com>
+
 	Phase one of the "fixnum" optimization (storing small enough
 	integers in the pointer). This just paves the way for the change
 	by making all the virtual functions of ValueImp private and adding
diff --git a/JavaScriptCore/ChangeLog-2003-10-25 b/JavaScriptCore/ChangeLog-2003-10-25
index 2d66890..314fa40 100644
--- a/JavaScriptCore/ChangeLog-2003-10-25
+++ b/JavaScriptCore/ChangeLog-2003-10-25
@@ -1,5 +1,52 @@
 2002-08-15  Maciej Stachowiak  <mjs at apple.com>
 
+	Phase 2 of fixnum optimization. Store any integral number that
+	will fit in two bits less than a long inside the ValueImp *
+	itself, thus avoiding the need to deal with the garbage collector
+	at all for these types. Such numbers comprised .5 million of the
+	1.7 million ValueImps created during the cvs-js-performance test,
+	so traffic through the garbage collector should be
+
+	20% improvement on cvs-js-performance. This may also show up on
+	cvs-base, but I did not compare and I am too lazy to make clean in
+	WebCore yet again. 
+
+	This also significantly reduces memory footprint on
+	JavaScript-heavy pages. Size after going through
+	cvs-js-performance suite is now 22MB to 17.5MB.
+	
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * kjs/simple_number.h: Added. Some inline static methods for handling
+	simple numbers that are stored in the pointer.
+        * kjs/ustring.h:
+        * kjs/ustring.cpp:
+        (UString::from): Added new overload for long.
+        * kjs/value.cpp:
+        (ValueImp::marked): Add special case for simple numbers.
+        (ValueImp::setGcAllowed): Likewise.
+	(ValueImp::toInteger): Call dispatch version of
+	toUInt32(unsigned&), not the real method.
+        (ValueImp::toInt32): Likewise.
+        (ValueImp::toUInt32): Likewise.
+        (ValueImp::toUInt16): Likewise.
+        (ValueImp::dispatchType): Add special case for simple numbers.
+        (ValueImp::dispatchToPrimitive): Likewise.
+        (ValueImp::dispatchToBoolean): Likewise.
+        (ValueImp::dispatchToNumber): Likewise.
+        (ValueImp::dispatchToString): Likewise.
+        (ValueImp::dispatchToObject): Likewise.
+        (ValueImp::dispatchToUInt32): Likewise.
+        (ValueImp::dispatchGetBase): Likewise.
+        (ValueImp::dispatchGetPropertyName): Likewise.
+        (ValueImp::dispatchPutValue): Likewise.
+        (ValueImp::dispatchDeleteValue): Likewise.
+        (Number::Number): Create a simple number instead of a full-blown
+	ValueImp when possible.
+        (Number::value): Likewise.
+        * kjs/value.h:
+
+2002-08-15  Maciej Stachowiak  <mjs at apple.com>
+
 	Phase one of the "fixnum" optimization (storing small enough
 	integers in the pointer). This just paves the way for the change
 	by making all the virtual functions of ValueImp private and adding
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index ee2bf5e..440a847 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -217,6 +217,7 @@
 				F692A8CD02555BA201FF60F7,
 				F68EBB8E0255D4C601FF60F7,
 				F5C290E70284F98E018635CA,
+				F50888B7030BB74C012A967E,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -368,6 +369,7 @@
 				F692A8860255597D01FF60F7,
 				F692A8870255597D01FF60F7,
 				F692A8880255597D01FF60F7,
+				F50888B6030BB74C012A967E,
 			);
 			isa = PBXGroup;
 			name = Classes;
@@ -422,6 +424,21 @@
 //F52
 //F53
 //F54
+		F50888B6030BB74C012A967E = {
+			isa = PBXFileReference;
+			name = simple_number.h;
+			path = kjs/simple_number.h;
+			refType = 4;
+		};
+		F50888B7030BB74C012A967E = {
+			fileRef = F50888B6030BB74C012A967E;
+			isa = PBXBuildFile;
+			settings = {
+				ATTRIBUTES = (
+					Private,
+				);
+			};
+		};
 		F531DDEB02F0C2DD018635CA = {
 			buildRules = (
 			);
diff --git a/JavaScriptCore/kjs/simple_number.h b/JavaScriptCore/kjs/simple_number.h
new file mode 100644
index 0000000..80c2918
--- /dev/null
+++ b/JavaScriptCore/kjs/simple_number.h
@@ -0,0 +1,49 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ *  This file is part of the KDE libraries
+ *  Copyright (C) 2002 Apple Computer, Inc
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ *  Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _KJS_SIMPLE_NUMBER_H_
+#define _KJS_SIMPLE_NUMBER_H_
+
+#include <limits.h>
+#include <math.h>
+
+namespace KJS {
+    class ValueImp;
+
+    class SimpleNumber {
+    public:
+	enum { TAG = 1, MASK = (1 + 2) };
+
+	static inline bool isSimpleNumber(const ValueImp *imp) { return ((long)imp & MASK) == TAG; }
+	static inline long longValue(const ValueImp *imp) { return ((long)imp & ~MASK) >> 2; } 
+	static inline bool fitsInSimpleNumber(int i) { return i < (LONG_MAX >> 2) && i > (LONG_MIN >> 2); }
+	static inline bool fitsInSimpleNumber(unsigned i) { return i < (unsigned)(LONG_MAX >> 2); }
+	static inline bool fitsInSimpleNumber(double d) { return d < (LONG_MAX >> 2) && d > (LONG_MIN >> 2) && remainder(d, 1) == 0; }
+
+	static inline bool fitsInSimpleNumber(long i) { return i < (LONG_MAX >> 2) && i > (LONG_MIN >> 2); }
+	static inline bool fitsInSimpleNumber(unsigned long i) { return i < (unsigned)(LONG_MAX >> 2); }
+
+	static inline ValueImp *makeSimpleNumber(long i) { return (ValueImp *)((i << 2) | TAG); }
+    };
+}
+
+#endif
diff --git a/JavaScriptCore/kjs/ustring.cpp b/JavaScriptCore/kjs/ustring.cpp
index 0991b47..503faef 100644
--- a/JavaScriptCore/kjs/ustring.cpp
+++ b/JavaScriptCore/kjs/ustring.cpp
@@ -263,6 +263,14 @@ UString UString::from(unsigned int u)
   return UString(buf);
 }
 
+UString UString::from(long l)
+{
+  char buf[40];
+  sprintf(buf, "%ld", l);
+
+  return UString(buf);
+}
+
 UString UString::from(double d)
 {
   char buf[40];
diff --git a/JavaScriptCore/kjs/ustring.h b/JavaScriptCore/kjs/ustring.h
index a1d1fa8..c573783 100644
--- a/JavaScriptCore/kjs/ustring.h
+++ b/JavaScriptCore/kjs/ustring.h
@@ -278,6 +278,10 @@ namespace KJS {
      */
     static UString from(unsigned int u);
     /**
+     * Constructs a string from a long.
+     */
+    static UString from(long l);
+    /**
      * Constructs a string from a double.
      */
     static UString from(double d);
diff --git a/JavaScriptCore/kjs/value.cpp b/JavaScriptCore/kjs/value.cpp
index d4e04b5..9fe9dd4 100644
--- a/JavaScriptCore/kjs/value.cpp
+++ b/JavaScriptCore/kjs/value.cpp
@@ -36,6 +36,7 @@
 #include "operations.h"
 #include "error_object.h"
 #include "nodes.h"
+#include "simple_number.h"
 
 using namespace KJS;
 
@@ -63,16 +64,18 @@ void ValueImp::mark()
 
 bool ValueImp::marked() const
 {
-  // FIXNUM: need special case for fixnum, they should act as if
-  // always marked.
-  return (_flags & VI_MARKED);
+  // simple numbers are always considered marked
+  return SimpleNumber::isSimpleNumber(this) || (_flags & VI_MARKED);
 }
 
 void ValueImp::setGcAllowed()
 {
-  // FIXNUM: need special case for fixnum, should be a no-op
-  //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this);
-  _flags |= VI_GCALLOWED;
+  // simple numbers are never seen by the collector so setting this
+  // flag is irrelevant
+  if (!SimpleNumber::isSimpleNumber(this)) {
+    //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this);
+    _flags |= VI_GCALLOWED;
+  }
 }
 
 void* ValueImp::operator new(size_t s)
@@ -94,7 +97,7 @@ bool ValueImp::toUInt32(unsigned&) const
 int ValueImp::toInteger(ExecState *exec) const
 {
   unsigned i;
-  if (toUInt32(i))
+  if (dispatchToUInt32(i))
     return (int)i;
   return int(roundValue(exec, Value(const_cast<ValueImp*>(this))));
 }
@@ -102,7 +105,7 @@ int ValueImp::toInteger(ExecState *exec) const
 int ValueImp::toInt32(ExecState *exec) const
 {
   unsigned i;
-  if (toUInt32(i))
+  if (dispatchToUInt32(i))
     return (int)i;
 
   double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
@@ -117,7 +120,7 @@ int ValueImp::toInt32(ExecState *exec) const
 unsigned int ValueImp::toUInt32(ExecState *exec) const
 {
   unsigned i;
-  if (toUInt32(i))
+  if (dispatchToUInt32(i))
     return i;
 
   double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
@@ -129,7 +132,7 @@ unsigned int ValueImp::toUInt32(ExecState *exec) const
 unsigned short ValueImp::toUInt16(ExecState *exec) const
 {
   unsigned i;
-  if (toUInt32(i))
+  if (dispatchToUInt32(i))
     return (unsigned short)i;
 
   double d = roundValue(exec, Value(const_cast<ValueImp*>(this)));
@@ -180,76 +183,109 @@ bool ValueImp::deleteValue(ExecState *exec)
 
 Type ValueImp::dispatchType() const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->type();
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return NumberType;
+  } else {
+    return this->type();
+  }
 }
 
 Value ValueImp::dispatchToPrimitive(ExecState *exec, Type preferredType) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toPrimitive(exec, preferredType);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return Number((NumberImp*)this);
+  } else {
+    return this->toPrimitive(exec, preferredType);
+  }
 }
 
 bool ValueImp::dispatchToBoolean(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toBoolean(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return SimpleNumber::longValue(this);
+  } else {
+    return this->toBoolean(exec);
+  }
 }
 
 double ValueImp::dispatchToNumber(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toNumber(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return SimpleNumber::longValue(this);
+  } else {
+    return this->toNumber(exec);
+  }
 }
 
 UString ValueImp::dispatchToString(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toString(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return UString::from(SimpleNumber::longValue(this));
+  } else {
+    return this->toString(exec);
+  }
 }
 
 Object ValueImp::dispatchToObject(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toObject(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+      List args;
+      args.append(Number(static_cast<NumberImp*>(const_cast<ValueImp *>(this))));
+      return Object::dynamicCast(exec->interpreter()->builtinNumber().construct(exec,args));
+  } else {
+    return this->toObject(exec);
+  }
 }
 
 bool ValueImp::dispatchToUInt32(unsigned& result) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->toUInt32(result);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    result = SimpleNumber::longValue(this);
+    return true;
+  } else {
+    return this->toUInt32(result);
+  }
 }
 
 Value ValueImp::dispatchGetBase(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->getBase(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    Object err = Error::create(exec, ReferenceError, I18N_NOOP("Invalid reference base"));
+    exec->setException(err);
+    return err;
+  } else {
+    return this->getBase(exec);
+  }
 }
 
 UString ValueImp::dispatchGetPropertyName(ExecState *exec) const
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->getPropertyName(exec);
-}
-
-#if 0
-Value ValueImp::dispatchGetValue(ExecState *exec) const
-{
-  // FIXNUM: need special case for fixnums here 
-  return this->getValue(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    return UString();
+  } else {
+    return this->getPropertyName(exec);
+  }
 }
-#endif
 
 void ValueImp::dispatchPutValue(ExecState *exec, const Value& w)
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->putValue(exec, w);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    Object err = Error::create(exec,ReferenceError);
+    exec->setException(err);
+  } else {
+    return this->putValue(exec, w);
+  }
 }
 
 bool ValueImp::dispatchDeleteValue(ExecState *exec)
 {
-  // FIXNUM: need special case for fixnums here 
-  return this->deleteValue(exec);
+  if (SimpleNumber::isSimpleNumber(this)) {
+    Object err = Error::create(exec,ReferenceError);
+    exec->setException(err);
+    return false;
+  } else {
+    return this->deleteValue(exec);
+  }
 }
 
 
@@ -371,25 +407,20 @@ String String::dynamicCast(const Value &v)
 
 // ------------------------------ Number ---------------------------------------
 
-// FIXNUM: need fixnum special case in below constructor
 Number::Number(int i)
-  : Value(new NumberImp(static_cast<double>(i))) { }
+  : Value(SimpleNumber::fitsInSimpleNumber(i) ? SimpleNumber::makeSimpleNumber(i) : new NumberImp(static_cast<double>(i))) { }
 
-// FIXNUM: need fixnum special case in below constructor
 Number::Number(unsigned int u)
-  : Value(new NumberImp(static_cast<double>(u))) { }
+  : Value(SimpleNumber::fitsInSimpleNumber(u) ? SimpleNumber::makeSimpleNumber(u) : new NumberImp(static_cast<double>(u))) { }
 
-// FIXNUM: need fixnum special case in below constructor
 Number::Number(double d)
-  : Value(new NumberImp(d)) { }
+  : Value(SimpleNumber::fitsInSimpleNumber((long)d) ? SimpleNumber::makeSimpleNumber((long)d) : new NumberImp(d)) { }
 
-// FIXNUM: need fixnum special case in below constructor
 Number::Number(long int l)
-  : Value(new NumberImp(static_cast<double>(l))) { }
+  : Value(SimpleNumber::fitsInSimpleNumber(l) ? SimpleNumber::makeSimpleNumber(l) : new NumberImp(static_cast<double>(l))) { }
 
-// FIXNUM: need fixnum special case in below constructor
 Number::Number(long unsigned int l)
-  : Value(new NumberImp(static_cast<double>(l))) { }
+  : Value(SimpleNumber::fitsInSimpleNumber(l) ? SimpleNumber::makeSimpleNumber(l) : new NumberImp(static_cast<double>(l))) { }
 
 Number Number::dynamicCast(const Value &v)
 {
@@ -401,8 +432,12 @@ Number Number::dynamicCast(const Value &v)
 
 double Number::value() const
 {
-  assert(rep);
-  return ((NumberImp*)rep)->value();
+  if (SimpleNumber::isSimpleNumber(rep)) {
+    return (double)SimpleNumber::longValue(rep);
+  } else {
+    assert(rep);
+    return ((NumberImp*)rep)->value();
+  }
 }
 
 int Number::intValue() const
diff --git a/JavaScriptCore/kjs/value.h b/JavaScriptCore/kjs/value.h
index 3972cb3..f30bece 100644
--- a/JavaScriptCore/kjs/value.h
+++ b/JavaScriptCore/kjs/value.h
@@ -37,6 +37,8 @@
 
 #include "ustring.h"
 
+#include "simple_number.h"
+
 // Primitive data types
 
 namespace KJS {
@@ -94,10 +96,9 @@ namespace KJS {
     ValueImp();
     virtual ~ValueImp();
 
+    inline ValueImp* ref() { if (!SimpleNumber::isSimpleNumber(this)) refcount++; return this; }
     // FIXNUM: need special case for fixnums below (should be no-op)
-    inline ValueImp* ref() { refcount++; return this; }
-    // FIXNUM: need special case for fixnums below (should be no-op)
-    inline bool deref() { return (!--refcount); }
+    inline bool deref() { if (SimpleNumber::isSimpleNumber(this)) return false; else return (!--refcount); }
     unsigned int refcount;
 
     virtual void mark();
@@ -400,6 +401,7 @@ namespace KJS {
    * Represents an primitive Number value
    */
   class Number : public Value {
+    friend class ValueImp;
   public:
     Number(int i);
     Number(unsigned int u);
@@ -429,8 +431,11 @@ namespace KJS {
   };
 
   inline Value ValueImp::dispatchGetValue(ExecState *exec) const {
-    // FIXNUM: need special case for fixnums here 
-    return this->getValue(exec);
+    if (SimpleNumber::isSimpleNumber(this)) {
+        return Value(const_cast<ValueImp*>(this));
+    } else {
+      return this->getValue(exec);
+    }
   }
 
 }; // namespace

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list