Contents in 1999-06-04-13 of release-21-2.
[chise/xemacs-chise.git.1] / src / print.c
index 663e3c4..8ded305 100644 (file)
@@ -806,37 +806,52 @@ float_to_string (char *buf, double data)
    faster.
 
    BUFFER should accept 24 bytes.  This should suffice for the longest
-   numbers on 64-bit machines.  */
+   numbers on 64-bit machines, including the `-' sign and the trailing
+   \0.  */
 void
 long_to_string (char *buffer, long number)
 {
-  char *p;
-  int i, len;
+#if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8)
+  /* Huh? */
+  sprintf (buffer, "%ld", number);
+#else /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
+  char *p = buffer;
+  int force = 0;
 
   if (number < 0)
     {
-      *buffer++ = '-';
+      *p++ = '-';
       number = -number;
     }
-  p = buffer;
 
-  /* Print the digits to the string.  */
-  do
-    {
-      *p++ = number % 10 + '0';
-      number /= 10;
-    }
-  while (number);
-
-  /* And reverse them.  */
-  len = p - buffer - 1;
-  for (i = len / 2; i >= 0; i--)
-    {
-      char c = buffer[i];
-      buffer[i] = buffer[len - i];
-      buffer[len - i] = c;
-    }
-  buffer[len + 1] = '\0';
+#define FROB(figure) do {                                              \
+    if (force || number >= figure)                                     \
+      *p++ = number / figure + '0', number %= figure, force = 1;       \
+    } while (0)
+#if SIZEOF_LONG == 8
+  FROB (1000000000000000000L);
+  FROB (100000000000000000L);
+  FROB (10000000000000000L);
+  FROB (1000000000000000L);
+  FROB (100000000000000L);
+  FROB (10000000000000L);
+  FROB (1000000000000L);
+  FROB (100000000000L);
+  FROB (10000000000L);
+#endif /* SIZEOF_LONG == 8 */
+  FROB (1000000000);
+  FROB (100000000);
+  FROB (10000000);
+  FROB (1000000);
+  FROB (100000);
+  FROB (10000);
+  FROB (1000);
+  FROB (100);
+  FROB (10);
+#undef FROB
+  *p++ = number + '0';
+  *p = '\0';
+#endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
 }
 \f
 static void
@@ -1093,12 +1108,8 @@ print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 
   switch (XTYPE (obj))
     {
-#ifdef USE_MINIMAL_TAGBITS
     case Lisp_Type_Int_Even:
     case Lisp_Type_Int_Odd:
-#else
-    case Lisp_Type_Int:
-#endif
       {
        char buf[24];
        long_to_string (buf, XINT (obj));
@@ -1146,68 +1157,11 @@ print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
        break;
       }
 
-#ifndef LRECORD_STRING
-    case Lisp_Type_String:
-      {
-       print_string (obj, printcharfun, escapeflag);
-       break;
-      }
-#endif /* ! LRECORD_STRING */
-
-#ifndef LRECORD_CONS
-    case Lisp_Type_Cons:
-      {
-       struct gcpro gcpro1, gcpro2;
-
-       /* If deeper than spec'd depth, print placeholder.  */
-       if (INTP (Vprint_level)
-           && print_depth > XINT (Vprint_level))
-         {
-           GCPRO2 (obj, printcharfun);
-           write_c_string ("...", printcharfun);
-           UNGCPRO;
-           break;
-         }
-
-       print_cons (obj, printcharfun, escapeflag);
-       break;
-      }
-#endif /* ! LRECORD_CONS */
-
-#ifndef LRECORD_VECTOR
-    case Lisp_Type_Vector:
-      {
-       /* If deeper than spec'd depth, print placeholder.  */
-       if (INTP (Vprint_level)
-           && print_depth > XINT (Vprint_level))
-         {
-           struct gcpro gcpro1, gcpro2;
-           GCPRO2 (obj, printcharfun);
-           write_c_string ("...", printcharfun);
-           UNGCPRO;
-           break;
-         }
-
-       /* God intended that this be #(...), you know. */
-       print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
-       break;
-      }
-#endif /* !LRECORD_VECTOR */
-
-#ifndef LRECORD_SYMBOL
-    case Lisp_Type_Symbol:
-      {
-        print_symbol (obj, printcharfun, escapeflag);
-        break;
-      }
-#endif /* !LRECORD_SYMBOL */
-
     case Lisp_Type_Record:
       {
        struct lrecord_header *lheader = XRECORD_LHEADER (obj);
        struct gcpro gcpro1, gcpro2;
 
-#if defined(LRECORD_CONS) || defined(LRECORD_VECTOR)
        if (CONSP (obj) || VECTORP(obj))
          {
            /* If deeper than spec'd depth, print placeholder.  */
@@ -1220,7 +1174,6 @@ print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
                break;
              }
          }
-#endif
 
        GCPRO2 (obj, printcharfun);
        if (LHEADER_IMPLEMENTATION (lheader)->printer)
@@ -1292,7 +1245,12 @@ print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
   /* If we print an uninterned symbol as part of a complex object and
      the flag print-gensym is non-nil, prefix it with #n= to read the
      object back with the #n# reader syntax later if needed.  */
-  if (!NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
+  if (!NILP (Vprint_gensym)
+      /* #### Test whether this produces a noticable slow-down for
+         printing when print-gensym is non-nil.  */
+      && !EQ (obj, oblookup (Vobarray,
+                            string_data (symbol_name (XSYMBOL (obj))),
+                            string_length (symbol_name (XSYMBOL (obj))))))
     {
       if (print_depth > 1)
        {