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
6a60ac33
Commit
6a60ac33
authored
Jan 27, 2009
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String optimisations
parent
49fcd4f7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
CodedInputStream.cs
src/ProtocolBuffers/CodedInputStream.cs
+6
-3
No files found.
src/ProtocolBuffers/CodedInputStream.cs
View file @
6a60ac33
...
@@ -219,17 +219,20 @@ namespace Google.ProtocolBuffers {
...
@@ -219,17 +219,20 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
public
String
ReadString
()
{
public
String
ReadString
()
{
int
size
=
(
int
)
ReadRawVarint32
();
int
size
=
(
int
)
ReadRawVarint32
();
if
(
size
<
bufferSize
-
bufferPos
&&
size
>
0
)
{
// No need to read any data for an empty string.
if
(
size
==
0
)
{
return
""
;
}
if
(
size
<=
bufferSize
-
bufferPos
)
{
// Fast path: We already have the bytes in a contiguous buffer, so
// Fast path: We already have the bytes in a contiguous buffer, so
// just copy directly from it.
// just copy directly from it.
String
result
=
Encoding
.
UTF8
.
GetString
(
buffer
,
bufferPos
,
size
);
String
result
=
Encoding
.
UTF8
.
GetString
(
buffer
,
bufferPos
,
size
);
bufferPos
+=
size
;
bufferPos
+=
size
;
return
result
;
return
result
;
}
else
{
}
// Slow path: Build a byte array first then copy it.
// Slow path: Build a byte array first then copy it.
return
Encoding
.
UTF8
.
GetString
(
ReadRawBytes
(
size
));
return
Encoding
.
UTF8
.
GetString
(
ReadRawBytes
(
size
));
}
}
}
/// <summary>
/// <summary>
/// Reads a group field value from the stream.
/// Reads a group field value from the stream.
...
...
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