simple-mmap 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/ext/simple_mmap/mapped_file.c +7 -16
  2. metadata +2 -2
@@ -118,31 +118,22 @@ static VALUE sm_mapped_file_read_window_data(VALUE vself, VALUE voffset, VALUE v
118
118
  {
119
119
  size_t offset = NUM2INT(voffset);
120
120
  size_t length = NUM2INT(vlength);
121
- char buff[length];
122
121
  VALUE vsm_map;
123
122
  simple_mmap_map *sm_map;
124
123
 
125
124
  vsm_map = rb_ivar_get(vself, rb_intern("@mmap_data"));
126
125
  Data_Get_Struct(vsm_map, simple_mmap_map, sm_map);
127
126
 
128
- if (offset > sm_map->len) {
127
+ if (offset < 0 || offset > sm_map->len) {
129
128
  return Qnil;
130
129
  }
131
-
132
- size_t curr = offset;
133
- size_t i;
134
- for(i = 0; i < length; ++i) {
135
- //printf("i=%i offset=%i length=%i curr=%i map->len=%i\n", i, offset, length, curr, sm_map->len);
136
- if ((offset + i) > sm_map->len)
137
- break;
138
- buff[i] = sm_map->map[curr++];
139
- }
140
-
130
+
141
131
  // If the range overflows, return part that overlaps
142
- if ((offset + length) > sm_map->len)
143
- return rb_str_new(buff, sm_map->len - offset);
144
-
145
- return rb_str_new(buff, length);
132
+ if ((offset + length) > sm_map->len) {
133
+ length = sm_map->len - offset;
134
+ }
135
+
136
+ return rb_str_new(sm_map->map + offset, length);
146
137
  }
147
138
 
148
139
  /*
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-mmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Johan S\xC3\xB8rensen"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-10 00:00:00 +01:00
13
+ date: 2010-02-11 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency