diff lphobos/internal/objectimpl.d @ 58:2c3cd3596187 trunk

[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum Added initial support for CatExp aka 'a ~ b' Fixed global constant static arrays initialized with string literals Fixed casting any dynamic array to void* Fixed new expression with temporary storage Fixed alias declarations in function scope Fixed relational comparisons of pointers
author lindquist
date Thu, 25 Oct 2007 09:02:55 +0200
parents 28e99b04a132
children d7e764e62462
line wrap: on
line diff
--- a/lphobos/internal/objectimpl.d	Thu Oct 25 02:39:53 2007 +0200
+++ b/lphobos/internal/objectimpl.d	Thu Oct 25 09:02:55 2007 +0200
@@ -466,8 +466,6 @@
 {
 }
 
-/+
-
 class TypeInfo_Pointer : TypeInfo
 {
     char[] toString() { return m_next.toString() ~ "*"; }
@@ -595,11 +593,57 @@
     uint flags() { return 1; }
 }
 
+private const char[10] digits    = "0123456789";            /// 0..9
+
+private char[] lengthToString(uint u)
+{   char[uint.sizeof * 3] buffer = void;
+    int ndigits;
+    char[] result;
+
+    ndigits = 0;
+    if (u < 10)
+    // Avoid storage allocation for simple stuff
+    result = digits[u .. u + 1];
+    else
+    {
+    while (u)
+    {
+        uint c = (u % 10) + '0';
+        u /= 10;
+        ndigits++;
+        buffer[buffer.length - ndigits] = cast(char)c;
+    }
+    result = new char[ndigits];
+    result[] = buffer[buffer.length - ndigits .. buffer.length];
+    }
+    return result;
+}
+
+private char[] lengthToString(ulong u)
+{   char[ulong.sizeof * 3] buffer;
+    int ndigits;
+    char[] result;
+
+    if (u < 0x1_0000_0000)
+    return lengthToString(cast(uint)u);
+    ndigits = 0;
+    while (u)
+    {
+    char c = cast(char)((u % 10) + '0');
+    u /= 10;
+    ndigits++;
+    buffer[buffer.length - ndigits] = c;
+    }
+    result = new char[ndigits];
+    result[] = buffer[buffer.length - ndigits .. buffer.length];
+    return result;
+}
+
 class TypeInfo_StaticArray : TypeInfo
 {
     char[] toString()
     {
-    return value.toString() ~ "[" ~ std.string.toString(len) ~ "]";
+    return value.toString() ~ "[" ~ lengthToString(len) ~ "]";
     }
 
     int opEquals(Object o)
@@ -658,8 +702,12 @@
 
     if (sz < buffer.sizeof)
         tmp = buffer.ptr;
-    else
+    else {
+        if (value.flags() & 1)
         tmp = pbuffer = (new void[sz]).ptr;
+        else
+        tmp = pbuffer = (new byte[sz]).ptr;
+    }
 
     for (size_t u = 0; u < len; u += sz)
     {   size_t o = u * sz;
@@ -761,6 +809,8 @@
     TypeInfo next;
 }
 
+/+
+
 class TypeInfo_Class : TypeInfo
 {
     char[] toString() { return info.name; }
@@ -1041,6 +1091,8 @@
     }
 }
 
++/
+
 class TypeInfo_Const : TypeInfo
 {
     char[] toString() { return "const " ~ base.toString(); }
@@ -1064,8 +1116,6 @@
     char[] toString() { return "invariant " ~ base.toString(); }
 }
 
-+/
-
 /**
  * All recoverable exceptions should be derived from class Exception.
  */