summaryrefslogtreecommitdiff
path: root/core/ring_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/ring_buffer.h')
-rw-r--r--core/ring_buffer.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 3c13cb8d1e..8b32bb5e10 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -6,6 +6,7 @@
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -100,6 +101,32 @@ public:
return p_size;
};
+ int find(const T &t, int p_offset, int p_max_size) {
+
+ int left = data_left();
+ if ((p_offset + p_max_size) > left) {
+ p_max_size -= left - p_offset;
+ if (p_max_size <= 0)
+ return 0;
+ }
+ p_max_size = MIN(left, p_max_size);
+ int pos = read_pos;
+ inc(pos, p_offset);
+ int to_read = p_max_size;
+ while (to_read) {
+ int end = pos + to_read;
+ end = MIN(end, size());
+ int total = end - pos;
+ for (int i = 0; i < total; i++) {
+ if (data[pos + i] == t)
+ return i + (p_max_size - to_read);
+ };
+ to_read -= total;
+ pos = 0;
+ }
+ return -1;
+ }
+
inline int advance_read(int p_n) {
p_n = MIN(p_n, data_left());
inc(read_pos, p_n);