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
3faaac1b
Commit
3faaac1b
authored
Feb 07, 2015
by
csharptest
Committed by
rogerk
Feb 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
parent
f6a0c116
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
CodedInputStreamTest.cs
src/ProtocolBuffers.Test/CodedInputStreamTest.cs
+31
-0
CodedInputStream.cs
src/ProtocolBuffers/CodedInputStream.cs
+1
-1
No files found.
src/ProtocolBuffers.Test/CodedInputStreamTest.cs
View file @
3faaac1b
...
...
@@ -37,6 +37,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.TestProtos
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System.Diagnostics
;
...
...
@@ -605,5 +606,34 @@ namespace Google.ProtocolBuffers
Assert
.
AreEqual
(
4
,
unk
.
Count
);
}
//Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
[
TestMethod
]
public
void
TestSlowPathAvoidance
()
{
using
(
var
ms
=
new
MemoryStream
())
{
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
ms
);
output
.
WriteField
(
FieldType
.
Bytes
,
1
,
"bytes"
,
ByteString
.
CopyFrom
(
new
byte
[
100
]));
output
.
WriteField
(
FieldType
.
Bytes
,
2
,
"bytes"
,
ByteString
.
CopyFrom
(
new
byte
[
100
]));
output
.
Flush
();
ms
.
Position
=
0
;
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
ms
,
new
byte
[
ms
.
Length
/
2
]);
uint
tag
;
string
ignore
;
ByteString
value
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
ignore
));
Assert
.
AreEqual
(
1
,
WireFormat
.
GetTagFieldNumber
(
tag
));
value
=
ByteString
.
Empty
;
Assert
.
IsTrue
(
input
.
ReadBytes
(
ref
value
)
&&
value
.
Length
==
100
);
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
ignore
));
Assert
.
AreEqual
(
2
,
WireFormat
.
GetTagFieldNumber
(
tag
));
value
=
ByteString
.
Empty
;
Assert
.
IsTrue
(
input
.
ReadBytes
(
ref
value
)
&&
value
.
Length
==
100
);
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers/CodedInputStream.cs
View file @
3faaac1b
...
...
@@ -427,7 +427,7 @@ namespace Google.ProtocolBuffers
public
bool
ReadBytes
(
ref
ByteString
value
)
{
int
size
=
(
int
)
ReadRawVarint32
();
if
(
size
<
bufferSize
-
bufferPos
&&
size
>
0
)
if
(
size
<
=
bufferSize
-
bufferPos
&&
size
>
0
)
{
// Fast path: We already have the bytes in a contiguous buffer, so
// just copy directly from it.
...
...
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