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

Unified Diff: runtime/vm/json_stream.cc

Issue 1400393002: Use offset and count to request slices of lists, maps, and typed_data. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code review Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_stream.cc
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc
index 0f4f3a647dd79de3c8190b112486fa00e0f95663..0477bb48b78124206191ece696510a897d14ec91 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -30,7 +30,9 @@ JSONStream::JSONStream(intptr_t buf_size)
method_(""),
param_keys_(NULL),
param_values_(NULL),
- num_params_(0) {
+ num_params_(0),
+ offset_(0),
+ count_(-1) {
ObjectIdRing* ring = NULL;
Isolate* isolate = Isolate::Current();
if (isolate != NULL) {
@@ -245,6 +247,22 @@ bool JSONStream::ParamIs(const char* key, const char* value) const {
}
+void JSONStream::ComputeOffsetAndCount(intptr_t length,
+ intptr_t* offset,
+ intptr_t* count) {
+ // This function is written to avoid adding (count + offset) in case
+ // that triggers an integer overflow.
+ *offset = offset_;
+ if (*offset > length) {
+ *offset = length;
+ }
+ intptr_t remaining = length - *offset;
+ *count = count_;
+ if (*count < 0 || *count > remaining) {
+ *count = remaining;
+ }
+}
+
void JSONStream::Clear() {
buffer_.Clear();
open_objects_ = 0;
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698