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
ddb74eb6
Commit
ddb74eb6
authored
Jun 10, 2011
by
csharptest
Committed by
rogerk
Jun 10, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using List<Char> instead of StringBuilder for building strings from chars
parent
afe844bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
18 deletions
+17
-18
JsonTextCursor.cs
src/ProtocolBuffers/Serialization/JsonTextCursor.cs
+17
-18
No files found.
src/ProtocolBuffers/Serialization/JsonTextCursor.cs
View file @
ddb74eb6
...
@@ -156,7 +156,7 @@ namespace Google.ProtocolBuffers.Serialization
...
@@ -156,7 +156,7 @@ namespace Google.ProtocolBuffers.Serialization
{
{
SkipWhitespace
();
SkipWhitespace
();
Consume
(
'"'
);
Consume
(
'"'
);
StringBuilder
sb
=
new
StringBuilder
(
);
List
<
Char
>
sb
=
new
List
<
char
>(
100
);
while
(
_next
!=
'"'
)
while
(
_next
!=
'"'
)
{
{
if
(
_next
==
'\\'
)
if
(
_next
==
'\\'
)
...
@@ -165,54 +165,53 @@ namespace Google.ProtocolBuffers.Serialization
...
@@ -165,54 +165,53 @@ namespace Google.ProtocolBuffers.Serialization
char
ch
=
ReadChar
();
char
ch
=
ReadChar
();
switch
(
ch
)
switch
(
ch
)
{
{
case
'b'
:
sb
.
A
ppen
d
(
'\b'
);
break
;
case
'b'
:
sb
.
A
d
d
(
'\b'
);
break
;
case
'f'
:
sb
.
A
ppen
d
(
'\f'
);
break
;
case
'f'
:
sb
.
A
d
d
(
'\f'
);
break
;
case
'n'
:
sb
.
A
ppen
d
(
'\n'
);
break
;
case
'n'
:
sb
.
A
d
d
(
'\n'
);
break
;
case
'r'
:
sb
.
A
ppen
d
(
'\r'
);
break
;
case
'r'
:
sb
.
A
d
d
(
'\r'
);
break
;
case
't'
:
sb
.
A
ppen
d
(
'\t'
);
break
;
case
't'
:
sb
.
A
d
d
(
'\t'
);
break
;
case
'u'
:
case
'u'
:
{
{
string
hex
=
new
string
(
new
char
[]
{
ReadChar
(),
ReadChar
(),
ReadChar
(),
ReadChar
()
});
string
hex
=
new
string
(
new
char
[]
{
ReadChar
(),
ReadChar
(),
ReadChar
(),
ReadChar
()
});
int
result
;
int
result
;
Assert
(
int
.
TryParse
(
hex
,
NumberStyles
.
AllowHexSpecifier
,
CultureInfo
.
InvariantCulture
,
out
result
),
Assert
(
int
.
TryParse
(
hex
,
NumberStyles
.
AllowHexSpecifier
,
CultureInfo
.
InvariantCulture
,
out
result
),
"Expected a 4-character hex specifier."
);
"Expected a 4-character hex specifier."
);
sb
.
A
ppen
d
((
char
)
result
);
sb
.
A
d
d
((
char
)
result
);
break
;
break
;
}
}
default
:
default
:
sb
.
A
ppen
d
(
ch
);
break
;
sb
.
A
d
d
(
ch
);
break
;
}
}
}
}
else
else
{
{
Assert
(
_next
!=
'\n'
&&
_next
!=
'\r'
&&
_next
!=
'\f'
&&
_next
!=
-
1
,
'"'
);
Assert
(
_next
!=
'\n'
&&
_next
!=
'\r'
&&
_next
!=
'\f'
&&
_next
!=
-
1
,
'"'
);
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
}
}
}
}
Consume
(
'"'
);
Consume
(
'"'
);
return
sb
.
ToString
(
);
return
new
String
(
sb
.
ToArray
()
);
}
}
public
string
ReadNumber
()
public
string
ReadNumber
()
{
{
SkipWhitespace
();
SkipWhitespace
();
List
<
Char
>
sb
=
new
List
<
char
>(
24
);
StringBuilder
sb
=
new
StringBuilder
();
if
(
_next
==
'-'
)
if
(
_next
==
'-'
)
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
Assert
(
_next
>=
'0'
&&
_next
<=
'9'
,
"Expected a numeric type."
);
Assert
(
_next
>=
'0'
&&
_next
<=
'9'
,
"Expected a numeric type."
);
while
((
_next
>=
'0'
&&
_next
<=
'9'
)
||
_next
==
'.'
)
while
((
_next
>=
'0'
&&
_next
<=
'9'
)
||
_next
==
'.'
)
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
if
(
_next
==
'e'
||
_next
==
'E'
)
if
(
_next
==
'e'
||
_next
==
'E'
)
{
{
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
if
(
_next
==
'-'
||
_next
==
'+'
)
if
(
_next
==
'-'
||
_next
==
'+'
)
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
Assert
(
_next
>=
'0'
&&
_next
<=
'9'
,
"Expected a numeric type."
);
Assert
(
_next
>=
'0'
&&
_next
<=
'9'
,
"Expected a numeric type."
);
while
(
_next
>=
'0'
&&
_next
<=
'9'
)
while
(
_next
>=
'0'
&&
_next
<=
'9'
)
sb
.
A
ppen
d
(
ReadChar
());
sb
.
A
d
d
(
ReadChar
());
}
}
return
sb
.
ToString
(
);
return
new
String
(
sb
.
ToArray
()
);
}
}
public
JsType
ReadVariant
(
out
object
value
)
public
JsType
ReadVariant
(
out
object
value
)
...
...
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