Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
e23f6461
Commit
e23f6461
authored
13 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Cache the return value of Arrays.hashCode().
parent
b72a90be
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/net/sf/briar/api/Bytes.java
+6
-1
6 additions, 1 deletion
api/net/sf/briar/api/Bytes.java
api/net/sf/briar/api/protocol/UniqueId.java
+6
-1
6 additions, 1 deletion
api/net/sf/briar/api/protocol/UniqueId.java
with
12 additions
and
2 deletions
api/net/sf/briar/api/Bytes.java
+
6
−
1
View file @
e23f6461
...
@@ -7,6 +7,8 @@ public class Bytes {
...
@@ -7,6 +7,8 @@ public class Bytes {
private
final
byte
[]
bytes
;
private
final
byte
[]
bytes
;
private
int
hashCode
=
-
1
;
public
Bytes
(
byte
[]
bytes
)
{
public
Bytes
(
byte
[]
bytes
)
{
this
.
bytes
=
bytes
;
this
.
bytes
=
bytes
;
}
}
...
@@ -17,7 +19,10 @@ public class Bytes {
...
@@ -17,7 +19,10 @@ public class Bytes {
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Arrays
.
hashCode
(
bytes
);
// Thread-safe because if two or more threads check and update the
// value, they'll calculate the same value
if
(
hashCode
==
-
1
)
hashCode
=
Arrays
.
hashCode
(
bytes
);
return
hashCode
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
api/net/sf/briar/api/protocol/UniqueId.java
+
6
−
1
View file @
e23f6461
...
@@ -9,6 +9,8 @@ public abstract class UniqueId {
...
@@ -9,6 +9,8 @@ public abstract class UniqueId {
protected
final
byte
[]
id
;
protected
final
byte
[]
id
;
private
int
hashCode
=
-
1
;
protected
UniqueId
(
byte
[]
id
)
{
protected
UniqueId
(
byte
[]
id
)
{
assert
id
.
length
==
LENGTH
;
assert
id
.
length
==
LENGTH
;
this
.
id
=
id
;
this
.
id
=
id
;
...
@@ -20,6 +22,9 @@ public abstract class UniqueId {
...
@@ -20,6 +22,9 @@ public abstract class UniqueId {
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Arrays
.
hashCode
(
id
);
// Thread-safe because if two or more threads check and update the
// value, they'll calculate the same value
if
(
hashCode
==
-
1
)
hashCode
=
Arrays
.
hashCode
(
id
);
return
hashCode
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment