1
0
mirror of https://github.com/google/uuid.git synced 2025-07-05 00:58:42 +02:00
Commit Graph

18 Commits

Author SHA1 Message Date
ca12c440f3 Merge pull request #5 from bmatsuo/bmatsuo/no-unsafe-parsing
optimize internal parsing function -- avoid unsafe []byte parsing
2016-02-29 06:12:54 -08:00
3018594d88 misc godoc fixes
Fairly simple typos.  The only peculiar thing is the godoc comment for
UUID.Version().
2016-02-28 00:52:46 -08:00
7508f98c71 optimize internal parsing function -- avoid unsafe []byte parsing
Making xtob take two byte arguments avoids a lot of slicing.  This makes
the Parse function faster.  In addition, because so much slicing is
avoiding, duplicating the parse logic to ParseBytes resulted in the
function being faster than Parse (<1ns).

The BenchmarkParseBytesNative function has been removed (parseBytes was
identical to ParseBytes).  And a new benchmark,
BenchmarkParseBytesUnsafe, has been added to benchmark the old way of
parsing []byte (which is slightly slower than Parse and thus the new
ParseBytes implementation).

    benchmark                         old ns/op     new ns/op     delta
    BenchmarkUUID_MarshalJSON-4       685           667           -2.63%
    BenchmarkUUID_UnmarshalJSON-4     1145          1162          +1.48%
    BenchmarkParse-4                  61.6          56.5          -8.28%
    BenchmarkParseBytes-4             65.7          55.9          -14.92%
    BenchmarkParseBytesCopy-4         121           115           -4.96%
    BenchmarkNew-4                    1665          1643          -1.32%
    BenchmarkUUID_String-4            112           113           +0.89%
    BenchmarkUUID_URN-4               117           119           +1.71%

    benchmark                         old allocs     new allocs     delta
    BenchmarkUUID_MarshalJSON-4       4              4              +0.00%
    BenchmarkUUID_UnmarshalJSON-4     2              2              +0.00%
    BenchmarkParse-4                  0              0              +0.00%
    BenchmarkParseBytes-4             0              0              +0.00%
    BenchmarkParseBytesCopy-4         1              1              +0.00%
    BenchmarkNew-4                    1              1              +0.00%
    BenchmarkUUID_String-4            1              1              +0.00%
    BenchmarkUUID_URN-4               1              1              +0.00%

    benchmark                         old bytes     new bytes     delta
    BenchmarkUUID_MarshalJSON-4       248           248           +0.00%
    BenchmarkUUID_UnmarshalJSON-4     248           248           +0.00%
    BenchmarkParse-4                  0             0             +0.00%
    BenchmarkParseBytes-4             0             0             +0.00%
    BenchmarkParseBytesCopy-4         48            48            +0.00%
    BenchmarkNew-4                    16            16            +0.00%
    BenchmarkUUID_String-4            48            48            +0.00%
    BenchmarkUUID_URN-4               48            48            +0.00%
2016-02-25 21:48:37 -08:00
7dd4798941 replace Must* funcs with a single generic Must func
The MustParse and MustNewUUID functions have been removed since they
can be replaced simply using the new function.

    uuid.Must(uuid.Parse(s))
    uuid.Must(uuid.NewUUID())

This also fixes a spurious bug in the UnmarshalJSON method that
prevented compiling the json.go file.
2016-02-25 20:56:08 -08:00
9e951e1b07 Change a UUID from []byte to [16]byte along with other API changes. 2016-02-19 12:30:25 -08:00
be63595eee add method Array.String() 2016-02-12 08:02:43 -08:00
b4118685bb define Array type to convert UUIDs to/from map keys. 2016-02-11 12:00:09 -08:00
27e2c5ea7b Merge pull request #13 from bmatsuo/optimizations
Optimizations
2016-02-09 10:14:57 -08:00
6cc520cd8b Fix govet issues and make node.go thread safe.
Includes changes from mischief and shawnps.
2016-02-09 09:58:31 -08:00
1ea597af03 typo 2016-01-22 08:36:40 -08:00
1c7b0fea16 opitimize json interface methods
A common helper function is used for UUID.String(), UUID.URN(), and
UUID.MarshalJSON().  Any perforance hit in UUID.String() and
UUID.Marshal() appears to be negligable.  The benefit to
UUID.MarshalJSON() is several hundred nanoseconds (23% faster) and 2
allocations (21% fewer bytes).

Some redundant checks are removed from UUID.UnmarshalJSON() method.  The
"encoding/json".Unmarshaler interface specifies that implementations can
assume input is valid JSON content.  This allows one to assume that (1)
input is not empty and (2) if index 0 is a quote, then the content is a
json string and the last index will contain a terminating quote.  The
second point is not completely explicit in the documentation but it is
true in practice (and it is safe to assume -- errors will be caught).
2015-10-10 22:08:33 -07:00
0ec82b41c6 remove redundant nil checks in UUID.String() and UUID.URN() 2015-10-10 21:41:29 -07:00
9e4836cc57 do not use fmt.Sprintf() in UUID.URN()
The procedure is the same as UUID.String() (see f4e3abb).  Code is not
shared to ensure that unnecessary bounds checks do not occur.
2015-10-10 21:41:29 -07:00
71fb85a64c do not use fmt.Sprintf() in UUID.String()
A single array is used as a buffer and "encoding/hex".Encode() hex
encodes directly its final destination.  Loops are avoided because they
are simple enough to unroll manually.
2015-10-10 21:41:29 -07:00
4e1e17316e use arrays in Parse() for reduced allocation cost and bounds checks
An array is also for hex digit value lookups which seemed to reliably
give a few ns reduction in time.
2015-10-10 21:12:40 -07:00
2a573a0b4d Move code up one directory 2015-06-03 14:39:07 -07:00
808d470594 uuid: source re-organization
Move source to uuid subdirectory.
Add in coderviewability.

R=rsc
CC=borman
http://codereview.appspot.com/4838053
2011-08-08 14:34:29 -07:00
e130d97558 Initial checking of the go-uuid code. 2011-08-08 11:45:10 -07:00