prism 0.20.0 → 0.22.0

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.
@@ -181,6 +181,31 @@ pm_constant_pool_id_to_constant(const pm_constant_pool_t *pool, pm_constant_id_t
181
181
  return &pool->constants[constant_id - 1];
182
182
  }
183
183
 
184
+ /**
185
+ * Find a constant in a constant pool. Returns the id of the constant, or 0 if
186
+ * the constant is not found.
187
+ */
188
+ pm_constant_id_t
189
+ pm_constant_pool_find(pm_constant_pool_t *pool, const uint8_t *start, size_t length) {
190
+ assert(is_power_of_two(pool->capacity));
191
+ const uint32_t mask = pool->capacity - 1;
192
+
193
+ uint32_t hash = pm_constant_pool_hash(start, length);
194
+ uint32_t index = hash & mask;
195
+ pm_constant_pool_bucket_t *bucket;
196
+
197
+ while (bucket = &pool->buckets[index], bucket->id != PM_CONSTANT_ID_UNSET) {
198
+ pm_constant_t *constant = &pool->constants[bucket->id - 1];
199
+ if ((constant->length == length) && memcmp(constant->start, start, length) == 0) {
200
+ return bucket->id;
201
+ }
202
+
203
+ index = (index + 1) & mask;
204
+ }
205
+
206
+ return PM_CONSTANT_ID_UNSET;
207
+ }
208
+
184
209
  /**
185
210
  * Insert a constant into a constant pool and return its index in the pool.
186
211
  */
data/src/util/pm_string.c CHANGED
@@ -65,7 +65,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
65
65
  HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
66
66
 
67
67
  if (file == INVALID_HANDLE_VALUE) {
68
- perror("CreateFile failed");
69
68
  return false;
70
69
  }
71
70
 
@@ -73,7 +72,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
73
72
  DWORD file_size = GetFileSize(file, NULL);
74
73
  if (file_size == INVALID_FILE_SIZE) {
75
74
  CloseHandle(file);
76
- perror("GetFileSize failed");
77
75
  return false;
78
76
  }
79
77
 
@@ -90,7 +88,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
90
88
  HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
91
89
  if (mapping == NULL) {
92
90
  CloseHandle(file);
93
- perror("CreateFileMapping failed");
94
91
  return false;
95
92
  }
96
93
 
@@ -100,7 +97,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
100
97
  CloseHandle(file);
101
98
 
102
99
  if (source == NULL) {
103
- perror("MapViewOfFile failed");
104
100
  return false;
105
101
  }
106
102
 
@@ -110,7 +106,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
110
106
  // Open the file for reading
111
107
  int fd = open(filepath, O_RDONLY);
112
108
  if (fd == -1) {
113
- perror("open");
114
109
  return false;
115
110
  }
116
111
 
@@ -118,7 +113,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
118
113
  struct stat sb;
119
114
  if (fstat(fd, &sb) == -1) {
120
115
  close(fd);
121
- perror("fstat");
122
116
  return false;
123
117
  }
124
118
 
@@ -135,7 +129,6 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) {
135
129
 
136
130
  source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
137
131
  if (source == MAP_FAILED) {
138
- perror("Map failed");
139
132
  return false;
140
133
  }
141
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-01 00:00:00.000000000 Z
11
+ date: 2024-02-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -137,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 3.0.0
140
+ version: 2.7.0
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.4.1
147
+ rubygems_version: 3.6.0.dev
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Prism Ruby parser