Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ecaf329b
authored
Apr 10, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Improve ParsableByteArray performance + enhance API.
parent
ed658b8e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
View file @
ecaf329b
...
...
@@ -37,6 +37,12 @@ public final class ParsableByteArray {
limit
=
data
.
length
;
}
/** Creates a new instance wrapping {@code data}. */
public
ParsableByteArray
(
byte
[]
data
)
{
this
.
data
=
data
;
limit
=
data
.
length
;
}
/**
* Creates a new instance that wraps an existing array.
*
...
...
@@ -171,6 +177,13 @@ public final class ParsableByteArray {
return
result
;
}
/** Reads the next three bytes as an unsigned value. */
public
int
readUnsignedInt24
()
{
int
result
=
shiftIntoInt
(
data
,
position
,
3
);
position
+=
3
;
return
result
;
}
/** Reads the next four bytes as an unsigned value. */
public
long
readUnsignedInt
()
{
long
result
=
shiftIntoLong
(
data
,
position
,
4
);
...
...
@@ -180,9 +193,11 @@ public final class ParsableByteArray {
/** Reads the next four bytes as a signed value. */
public
int
readInt
()
{
int
result
=
shiftIntoInt
(
data
,
position
,
4
);
position
+=
4
;
return
result
;
// shiftIntoInt inlined as performance optimization.
return
(
data
[
position
++]
&
0xFF
)
<<
24
|
(
data
[
position
++]
&
0xFF
)
<<
16
|
(
data
[
position
++]
&
0xFF
)
<<
8
|
data
[
position
++]
&
0xFF
;
}
/** Reads the next eight bytes as a signed value. */
...
...
@@ -221,8 +236,11 @@ public final class ParsableByteArray {
* @throws IllegalArgumentException Thrown if the top bit of the input data is set.
*/
public
int
readUnsignedIntToInt
()
{
int
result
=
shiftIntoInt
(
data
,
position
,
4
);
position
+=
4
;
// shiftIntoInt inlined as performance optimization.
final
int
result
=
(
data
[
position
++]
&
0xFF
)
<<
24
|
(
data
[
position
++]
&
0xFF
)
<<
16
|
(
data
[
position
++]
&
0xFF
)
<<
8
|
data
[
position
++]
&
0xFF
;
if
(
result
<
0
)
{
throw
new
IllegalArgumentException
(
"Top bit not zero: "
+
result
);
}
...
...
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