Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Protocol Buffers - Google's data interchange format 2 * Protocol Buffers - Google's data interchange format
3 * Copyright 2014 Google Inc. All rights reserved. 3 * Copyright 2014 Google Inc. All rights reserved.
4 * https://developers.google.com/protocol-buffers/ 4 * https://developers.google.com/protocol-buffers/
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 /* 103 /*
104 * call-seq: 104 * call-seq:
105 * RepeatedField.[]=(index, value) 105 * RepeatedField.[]=(index, value)
106 * 106 *
107 * Sets the element at the given index. On out-of-bounds assignments, extend s 107 * Sets the element at the given index. On out-of-bounds assignments, extend s
108 * the array and fills the hole (if any) with default values. 108 * the array and fills the hole (if any) with default values.
109 */ 109 */
110 @JRubyMethod(name = "[]=") 110 @JRubyMethod(name = "[]=")
111 public IRubyObject indexSet(ThreadContext context, IRubyObject index, IRubyO bject value) { 111 public IRubyObject indexSet(ThreadContext context, IRubyObject index, IRubyO bject value) {
112 int arrIndex = normalizeArrayIndex(index); 112 int arrIndex = normalizeArrayIndex(index);
113 Utils.checkType(context, fieldType, value, (RubyModule) typeClass); 113 value = Utils.checkType(context, fieldType, value, (RubyModule) typeClas s);
114 IRubyObject defaultValue = defaultValue(context); 114 IRubyObject defaultValue = defaultValue(context);
115 for (int i = this.storage.size(); i < arrIndex; i++) { 115 for (int i = this.storage.size(); i < arrIndex; i++) {
116 this.storage.set(i, defaultValue); 116 this.storage.set(i, defaultValue);
117 } 117 }
118 this.storage.set(arrIndex, value); 118 this.storage.set(arrIndex, value);
119 return context.runtime.getNil(); 119 return context.runtime.getNil();
120 } 120 }
121 121
122 /* 122 /*
123 * call-seq: 123 * call-seq:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 /* 159 /*
160 * call-seq: 160 * call-seq:
161 * RepeatedField.push(value) 161 * RepeatedField.push(value)
162 * 162 *
163 * Adds a new element to the repeated field. 163 * Adds a new element to the repeated field.
164 */ 164 */
165 @JRubyMethod(name = {"push", "<<"}) 165 @JRubyMethod(name = {"push", "<<"})
166 public IRubyObject push(ThreadContext context, IRubyObject value) { 166 public IRubyObject push(ThreadContext context, IRubyObject value) {
167 if (!(fieldType == Descriptors.FieldDescriptor.Type.MESSAGE && 167 if (!(fieldType == Descriptors.FieldDescriptor.Type.MESSAGE &&
168 value == context.runtime.getNil())) { 168 value == context.runtime.getNil())) {
169 Utils.checkType(context, fieldType, value, (RubyModule) typeClass); 169 value = Utils.checkType(context, fieldType, value, (RubyModule) type Class);
170 } 170 }
171 this.storage.add(value); 171 this.storage.add(value);
172 return this.storage; 172 return this.storage;
173 } 173 }
174 174
175 /* 175 /*
176 * private Ruby method used by RepeatedField.pop 176 * private Ruby method used by RepeatedField.pop
177 */ 177 */
178 @JRubyMethod(visibility = org.jruby.runtime.Visibility.PRIVATE) 178 @JRubyMethod(visibility = org.jruby.runtime.Visibility.PRIVATE)
179 public IRubyObject pop_one(ThreadContext context) { 179 public IRubyObject pop_one(ThreadContext context) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (arrIndex < 0 && arrSize > 0) { 400 if (arrIndex < 0 && arrSize > 0) {
401 arrIndex = arrSize + arrIndex; 401 arrIndex = arrSize + arrIndex;
402 } 402 }
403 return arrIndex; 403 return arrIndex;
404 } 404 }
405 405
406 private RubyArray storage; 406 private RubyArray storage;
407 private Descriptors.FieldDescriptor.Type fieldType; 407 private Descriptors.FieldDescriptor.Type fieldType;
408 private IRubyObject typeClass; 408 private IRubyObject typeClass;
409 } 409 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698