aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/main
diff options
context:
space:
mode:
authorWink Saville <wink@google.com>2010-06-07 17:04:13 -0700
committerWink Saville <wink@google.com>2010-06-07 17:04:13 -0700
commit1b639e09d77de609bed080f5d2ca88d72ba42559 (patch)
tree97e6183ede78002b0299d76c99ea65e9c8d0f23c /java/src/main
parenta3d3079a7ea18b2c052842272949247b7b4601e9 (diff)
downloadexternal_protobuf-1b639e09d77de609bed080f5d2ca88d72ba42559.zip
external_protobuf-1b639e09d77de609bed080f5d2ca88d72ba42559.tar.gz
external_protobuf-1b639e09d77de609bed080f5d2ca88d72ba42559.tar.bz2
Changed speed optimization for strings.
Removed use of StringUtf8Micro and instead use an extra byte array instance variable directly in the class. This allows the list returned for repeated strings to be a String instead of a StringUtf8Micro making the class compatible with existing code. Removed PerfTimer.java which isn't used. Change-Id: Ie6acfb40f98f59a48c1a795d86f715078f9611f5
Diffstat (limited to 'java/src/main')
-rw-r--r--java/src/main/java/com/google/protobuf/micro/CodedOutputStreamMicro.java67
-rw-r--r--java/src/main/java/com/google/protobuf/micro/StringUtf8Micro.java67
2 files changed, 32 insertions, 102 deletions
diff --git a/java/src/main/java/com/google/protobuf/micro/CodedOutputStreamMicro.java b/java/src/main/java/com/google/protobuf/micro/CodedOutputStreamMicro.java
index 68b6e97..0cb0774 100644
--- a/java/src/main/java/com/google/protobuf/micro/CodedOutputStreamMicro.java
+++ b/java/src/main/java/com/google/protobuf/micro/CodedOutputStreamMicro.java
@@ -179,13 +179,6 @@ public final class CodedOutputStreamMicro {
writeStringNoTag(value);
}
- /** Write a {@code StringUtf8Micro} field, including tag, to the stream. */
- public void writeStringUtf8(final int fieldNumber, final StringUtf8Micro value)
- throws IOException {
- writeTag(fieldNumber, WireFormatMicro.WIRETYPE_LENGTH_DELIMITED);
- writeStringUtf8NoTag(value);
- }
-
/** Write a {@code group} field, including tag, to the stream. */
public void writeGroup(final int fieldNumber, final MessageMicro value)
throws IOException {
@@ -208,6 +201,14 @@ public final class CodedOutputStreamMicro {
writeBytesNoTag(value);
}
+ /** Write a {@code byte} field, including tag, to the stream. */
+ public void writeByteArray(final int fieldNumber, final byte[] value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatMicro.WIRETYPE_LENGTH_DELIMITED);
+ writeByteArrayNoTag(value);
+ }
+
+
/** Write a {@code uint32} field, including tag, to the stream. */
public void writeUInt32(final int fieldNumber, final int value)
throws IOException {
@@ -336,13 +337,6 @@ public final class CodedOutputStreamMicro {
writeRawBytes(bytes);
}
- /** Write a {@code StringUtf8Micro} field to the stream. */
- public void writeStringUtf8NoTag(final StringUtf8Micro value) throws IOException {
- final byte[] bytes = value.getBytes();
- writeRawVarint32(bytes.length);
- writeRawBytes(bytes);
- }
-
/** Write a {@code group} field to the stream. */
public void writeGroupNoTag(final MessageMicro value) throws IOException {
value.writeTo(this);
@@ -361,6 +355,12 @@ public final class CodedOutputStreamMicro {
writeRawBytes(bytes);
}
+ /** Write a {@code byte[]} field to the stream. */
+ public void writeByteArrayNoTag(final byte [] value) throws IOException {
+ writeRawVarint32(value.length);
+ writeRawBytes(value);
+ }
+
/** Write a {@code uint32} field to the stream. */
public void writeUInt32NoTag(final int value) throws IOException {
writeRawVarint32(value);
@@ -475,15 +475,6 @@ public final class CodedOutputStreamMicro {
/**
* Compute the number of bytes that would be needed to encode a
- * {@code StringUtf8Micro} field, including tag.
- */
- public static int computeStringUtf8Size(final int fieldNumber,
- final StringUtf8Micro value) {
- return computeTagSize(fieldNumber) + computeStringUtf8SizeNoTag(value);
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a
* {@code group} field, including tag.
*/
public static int computeGroupSize(final int fieldNumber,
@@ -511,6 +502,15 @@ public final class CodedOutputStreamMicro {
/**
* Compute the number of bytes that would be needed to encode a
+ * {@code byte[]} field, including tag.
+ */
+ public static int computeByteArraySize(final int fieldNumber,
+ final byte[] value) {
+ return computeTagSize(fieldNumber) + computeByteArraySizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
* {@code uint32} field, including tag.
*/
public static int computeUInt32Size(final int fieldNumber, final int value) {
@@ -671,16 +671,6 @@ public final class CodedOutputStreamMicro {
/**
* Compute the number of bytes that would be needed to encode a
- * {@code StringUtf8Micro} field.
- */
- public static int computeStringUtf8SizeNoTag(final StringUtf8Micro value) {
- final byte[] bytes = value.getBytes();
- return computeRawVarint32Size(bytes.length) +
- bytes.length;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a
* {@code group} field.
*/
public static int computeGroupSizeNoTag(final MessageMicro value) {
@@ -701,8 +691,15 @@ public final class CodedOutputStreamMicro {
* {@code bytes} field.
*/
public static int computeBytesSizeNoTag(final ByteStringMicro value) {
- return computeRawVarint32Size(value.size()) +
- value.size();
+ return computeRawVarint32Size(value.size()) + value.size();
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code byte[]} field.
+ */
+ public static int computeByteArraySizeNoTag(final byte[] value) {
+ return computeRawVarint32Size(value.length) + value.length;
}
/**
diff --git a/java/src/main/java/com/google/protobuf/micro/StringUtf8Micro.java b/java/src/main/java/com/google/protobuf/micro/StringUtf8Micro.java
deleted file mode 100644
index 0c43e54..0000000
--- a/java/src/main/java/com/google/protobuf/micro/StringUtf8Micro.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package com.google.protobuf.micro;
-
-/**
- * A surogate for a String with a UTF8 representation.
- *
- * @author wink@google.com Wink Saville
- */
-public final class StringUtf8Micro {
- private String string;
- private byte[] bytes;
-
- public StringUtf8Micro(String string) {
- setString(string);
- }
-
- public static final StringUtf8Micro EMPTY = new StringUtf8Micro("");
-
- public String getString() {
- return string;
- }
-
- public void setString(String string) {
- this.string = string;
- bytes = null;
- }
-
- public byte [] getBytes() {
- if (bytes == null) {
- try {
- bytes = string.getBytes("UTF-8");
- } catch (java.io.UnsupportedEncodingException e) {
- throw new RuntimeException("UTF-8 not supported.");
- }
- }
- return bytes;
- }
-}