Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
92ac1ed6
Commit
92ac1ed6
authored
May 11, 2018
by
Anuraag Agrawal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unsafe no-copy String allocation since it's not useful in recent Java versions.
parent
7377d81c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
35 deletions
+2
-35
UnsafeUtil.java
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
+0
-27
Utf8.java
java/core/src/main/java/com/google/protobuf/Utf8.java
+2
-8
No files found.
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
View file @
92ac1ed6
...
@@ -33,7 +33,6 @@ package com.google.protobuf;
...
@@ -33,7 +33,6 @@ package com.google.protobuf;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.nio.Buffer
;
import
java.nio.Buffer
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.security.AccessController
;
import
java.security.AccessController
;
import
java.security.PrivilegedExceptionAction
;
import
java.security.PrivilegedExceptionAction
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
...
@@ -72,8 +71,6 @@ final class UnsafeUtil {
...
@@ -72,8 +71,6 @@ final class UnsafeUtil {
private
static
final
long
BUFFER_ADDRESS_OFFSET
=
fieldOffset
(
bufferAddressField
());
private
static
final
long
BUFFER_ADDRESS_OFFSET
=
fieldOffset
(
bufferAddressField
());
private
static
final
long
STRING_VALUE_OFFSET
=
fieldOffset
(
stringValueField
());
private
UnsafeUtil
()
{}
private
UnsafeUtil
()
{}
static
boolean
hasUnsafeArrayOperations
()
{
static
boolean
hasUnsafeArrayOperations
()
{
...
@@ -149,10 +146,6 @@ final class UnsafeUtil {
...
@@ -149,10 +146,6 @@ final class UnsafeUtil {
return
MEMORY_ACCESSOR
.
getObject
(
target
,
offset
);
return
MEMORY_ACCESSOR
.
getObject
(
target
,
offset
);
}
}
static
void
putObject
(
Object
target
,
long
offset
,
Object
value
)
{
MEMORY_ACCESSOR
.
putObject
(
target
,
offset
,
value
);
}
static
byte
getByte
(
byte
[]
target
,
long
index
)
{
static
byte
getByte
(
byte
[]
target
,
long
index
)
{
return
MEMORY_ACCESSOR
.
getByte
(
target
,
BYTE_ARRAY_BASE_OFFSET
+
index
);
return
MEMORY_ACCESSOR
.
getByte
(
target
,
BYTE_ARRAY_BASE_OFFSET
+
index
);
}
}
...
@@ -262,26 +255,6 @@ final class UnsafeUtil {
...
@@ -262,26 +255,6 @@ final class UnsafeUtil {
return
MEMORY_ACCESSOR
.
getLong
(
buffer
,
BUFFER_ADDRESS_OFFSET
);
return
MEMORY_ACCESSOR
.
getLong
(
buffer
,
BUFFER_ADDRESS_OFFSET
);
}
}
/**
* Returns a new {@link String} backed by the given {@code chars}. The char array should not
* be mutated any more after calling this function.
*/
static
String
moveToString
(
char
[]
chars
)
{
if
(
STRING_VALUE_OFFSET
==
-
1
)
{
// In the off-chance that this JDK does not implement String as we'd expect, just do a copy.
return
new
String
(
chars
);
}
final
String
str
;
try
{
str
=
(
String
)
UNSAFE
.
allocateInstance
(
String
.
class
);
}
catch
(
InstantiationException
e
)
{
// This should never happen, but return a copy as a fallback just in case.
return
new
String
(
chars
);
}
putObject
(
str
,
STRING_VALUE_OFFSET
,
chars
);
return
str
;
}
static
Object
getStaticObject
(
Field
field
)
{
static
Object
getStaticObject
(
Field
field
)
{
return
MEMORY_ACCESSOR
.
getStaticObject
(
field
);
return
MEMORY_ACCESSOR
.
getStaticObject
(
field
);
}
}
...
...
java/core/src/main/java/com/google/protobuf/Utf8.java
View file @
92ac1ed6
...
@@ -1474,10 +1474,7 @@ final class Utf8 {
...
@@ -1474,10 +1474,7 @@ final class Utf8 {
}
}
}
}
if
(
resultPos
<
resultArr
.
length
)
{
return
new
String
(
resultArr
,
0
,
resultPos
);
resultArr
=
Arrays
.
copyOf
(
resultArr
,
resultPos
);
}
return
UnsafeUtil
.
moveToString
(
resultArr
);
}
}
@Override
@Override
...
@@ -1553,10 +1550,7 @@ final class Utf8 {
...
@@ -1553,10 +1550,7 @@ final class Utf8 {
}
}
}
}
if
(
resultPos
<
resultArr
.
length
)
{
return
new
String
(
resultArr
,
0
,
resultPos
);
resultArr
=
Arrays
.
copyOf
(
resultArr
,
resultPos
);
}
return
UnsafeUtil
.
moveToString
(
resultArr
);
}
}
@Override
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment