File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
libs/x-content/src/main/java/org/elasticsearch/xcontent Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,23 @@ public static Text[] convertFromStringArray(String[] strings) {
3434 private ByteBuffer bytes ;
3535 private String text ;
3636 private int hash ;
37- private int length = -1 ;
37+ private int stringLength = -1 ;
3838
39+ /**
40+ * Construct a Text from a UTF-8 encoded ByteBuffer. Since no string length is specified, {@link #stringLength()}
41+ * will perform a string conversion to measure the string length.
42+ */
3943 public Text (ByteBuffer bytes ) {
4044 this .bytes = bytes ;
4145 }
4246
43- public Text (ByteBuffer bytes , int length ) {
47+ /**
48+ * Construct a Text from a UTF-8 encoded ByteBuffer and an explicit string length. Used to avoid string conversion
49+ * in {@link #stringLength()}.
50+ */
51+ public Text (ByteBuffer bytes , int stringLength ) {
4452 this .bytes = bytes ;
45- this .length = length ;
53+ this .stringLength = stringLength ;
4654 }
4755
4856 public Text (String text ) {
@@ -81,10 +89,10 @@ public String string() {
8189
8290 @ Override
8391 public int stringLength () {
84- if (length < 0 ) {
85- length = string ().length ();
92+ if (stringLength < 0 ) {
93+ stringLength = string ().length ();
8694 }
87- return length ;
95+ return stringLength ;
8896 }
8997
9098 @ Override
You can’t perform that action at this time.
0 commit comments