From: Rob Pike Date: Sun, 8 Feb 2009 18:16:32 +0000 (-0800) Subject: use unsafe.Sizeof X-Git-Tag: weekly.2009-11-06~2208 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9526f3b841275529cb5c5b9c1889b9bc359634b2;p=gostls13.git use unsafe.Sizeof R=rsc DELTA=9 (3 added, 3 deleted, 3 changed) OCL=24640 CL=24653 --- diff --git a/src/lib/reflect/type.go b/src/lib/reflect/type.go index 1dc95104d1..b02ad32d7a 100644 --- a/src/lib/reflect/type.go +++ b/src/lib/reflect/type.go @@ -10,6 +10,7 @@ package reflect import ( "utf8"; "sync"; + "unsafe"; ) type Type interface @@ -47,9 +48,11 @@ const ( UintptrKind; ) -// Int is guaranteed large enough to store a size. -var ptrsize int -var interfacesize int +var tmp_interface interface{} // used just to compute sizes of these constants +const ( + ptrsize = unsafe.Sizeof(&tmp_interface); + interfacesize = unsafe.Sizeof(tmp_interface); +) var missingString = "$missing$" // syntactic name for undefined type names var dotDotDotString = "..." @@ -401,9 +404,6 @@ func unlock() { } func init() { - ptrsize = 8; // TODO: compute this - interfacesize = 2*ptrsize; // TODO: compute this - lock(); // not necessary because of init ordering but be safe. types = make(map[string] Type);