From d8933e1ea576319250ffff88cfb9c3b9774f1a20 Mon Sep 17 00:00:00 2001 From: zeroZshadow Date: Fri, 10 Jun 2016 20:33:36 +0200 Subject: [PATCH] Added tests for MarshalJSON and UnmarshalJSON Reduced allocation of MarshalJSON from 65 to 40 B/op --- snowflake.go | 17 ++++++++++------- snowflake_test.go | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/snowflake.go b/snowflake.go index fa6b034..0327a6d 100644 --- a/snowflake.go +++ b/snowflake.go @@ -26,9 +26,10 @@ var Epoch int64 = 1288834974657 // node type Node struct { sync.Mutex - time int64 - node int64 - step int64 + time int64 + node int64 + step int64 + timebits int64 } // An ID is a custom type used for a snowflake ID. This is used so we can @@ -51,7 +52,7 @@ func NewNode(node int64) (*Node, error) { } // Generate creates and returns a unique snowflake ID -func (n *Node) Generate() (ID, error) { +func (n *Node) Generate() ID { n.Lock() defer n.Unlock() @@ -75,7 +76,7 @@ func (n *Node) Generate() (ID, error) { return ID((now-Epoch)<