threads/shared.pm: saves 4K per thread
Elizabeth Mattijsen [Fri, 5 Sep 2003 14:46:00 +0000 (16:46 +0200)]
Message-Id: <p05111b05bb7e177db044@[192.168.56.4]>
From: Elizabeth Mattijsen <liz@dijkmat.nl>

p4raw-id: //depot/perl@21047

ext/threads/shared/shared.pm

index 632040a..abeb1ac 100644 (file)
@@ -18,22 +18,22 @@ BEGIN {
        push @EXPORT,'bless';
     }
     else {
-       *share = \&share_disabled;
-       *cond_wait = \&cond_wait_disabled;
-       *cond_signal = \&cond_signal_disabled;
-       *cond_broadcast = \&cond_broadcast_disabled;
-    }
-}
 
+# String eval is generally evil, but we don't want these subs to exist at all
+# if threads are loaded successfully.  Vivifying them conditionally this way
+# saves on average about 4K of memory per thread.
 
-sub cond_wait_disabled      (\[$@%]) { undef }
-sub cond_signal_disabled    (\[$@%]) { undef }
-sub cond_broadcast_disabled (\[$@%]) { undef }
-sub share_disabled          (\[$@%]) { return $_[0] }
+        eval <<'EOD';
+sub cond_wait      (\[$@%]) { undef }
+sub cond_signal    (\[$@%]) { undef }
+sub cond_broadcast (\[$@%]) { undef }
+sub share          (\[$@%]) { return $_[0] }
+EOD
+    }
+}
 
 $threads::shared::threads_shared = 1;
 
-
 sub threads::shared::tie::SPLICE
 {
  die "Splice not implemented for shared arrays";