Skip to content

Commit

Permalink
Partial refactor to fix wall
Browse files Browse the repository at this point in the history
  • Loading branch information
rtheunissen committed Aug 8, 2016
1 parent 5b8a9de commit 31ad1f7
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 296 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ This project follows [Semantic Versioning](http://semver.org/).
### Fixed
- [x] Memory leaks during map when callback throws an exception.
- [x] Memory leaks when structures contain themselves.
- [x] Module dependencies.

## Added
- [x] Show version info in `phpinfo()`
- [x] Version info in `phpinfo()`

### Improvements
- [x] `Map::map` and `Map::filter` are now slightly faster.
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Combined class, name, and arginfo method entry.
*/
#define PHP_DS_ME(cls, name) \
PHP_ME(cls, name, arginfo_##name, ZEND_ACC_PUBLIC)
PHP_ME(cls, name, arginfo_##cls##_##name, ZEND_ACC_PUBLIC)

/**
*
Expand Down
35 changes: 9 additions & 26 deletions src/ds/ds_htable.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ static void ds_htable_copy(ds_htable_t *_src, ds_htable_t *_dst)
for (; src != end; ++src, ++dst) {
if ( ! DS_HTABLE_BUCKET_DELETED(src)) {
DS_HTABLE_BUCKET_COPY(dst, src);
} else {
DS_HTABLE_BUCKET_DELETE(dst);
}
}
}
Expand Down Expand Up @@ -680,7 +682,7 @@ void ds_htable_put(ds_htable_t *table, zval *key, zval *value)
ZVAL_COPY(&bucket->value, value);
}

static zval *create_zval_buffer_of_values(ds_htable_t *table)
zval *ds_htable_values(ds_htable_t *table)
{
zval *buffer = ALLOC_ZVAL_BUFFER(table->size);
zval *target = buffer;
Expand All @@ -694,26 +696,6 @@ static zval *create_zval_buffer_of_values(ds_htable_t *table)
return buffer;
}

static zval *create_zval_buffer_of_keys(ds_htable_t *table)
{
zval *buffer = ALLOC_ZVAL_BUFFER(table->size);
zval *target = buffer;
zval *key;

DS_HTABLE_FOREACH_KEY(table, key) {
ZVAL_COPY(target++, key);
}
DS_HTABLE_FOREACH_END();

return buffer;
}

ds_vector_t *ds_htable_values_to_vector(ds_htable_t *table)
{
zval *buffer = create_zval_buffer_of_values(table);
return ds_vector_from_buffer(buffer, table->size);
}

static ds_htable_bucket_t *get_last_bucket(ds_htable_t *table)
{
if (table->size > 0) {
Expand Down Expand Up @@ -839,10 +821,11 @@ ds_htable_t *ds_htable_slice(ds_htable_t *table, zend_long index, zend_long leng
/**
* If the table doesn't have any deleted buckets or if the first deleted
* bucket comes after the slice we're after, we can safely seek
* to the index and copy each bucket. We don't have to worry about
* increasing capacity or checking if a key already exists.
* to the index and copy each bucket.
*/
if (DS_HTABLE_IS_PACKED(table) || (index + length) <= table->min_deleted) {
if (DS_HTABLE_IS_PACKED(table) ||
((uint32_t) (index + length)) <= table->min_deleted) {

ds_htable_bucket_t *src = &table->buckets[index];

for (; length-- > 0; src++) {
Expand Down Expand Up @@ -953,7 +936,7 @@ ds_htable_t *ds_htable_map(ds_htable_t *table, FCI_PARAMS)

ds_htable_t *ds_htable_filter(ds_htable_t *table)
{
ds_htable_bucket_t *src, *dst;
ds_htable_bucket_t *src;

ds_htable_t *filtered = ds_htable_ex(table->capacity);

Expand All @@ -970,7 +953,7 @@ ds_htable_t *ds_htable_filter(ds_htable_t *table)

ds_htable_t *ds_htable_filter_callback(ds_htable_t *table, FCI_PARAMS)
{
ds_htable_bucket_t *src, *dst;
ds_htable_bucket_t *src;
zval retval;

ds_htable_t *filtered = ds_htable_ex(table->capacity);
Expand Down
3 changes: 1 addition & 2 deletions src/ds/ds_htable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define DS_HTABLE_H

#include "../common.h"
#include "ds_vector.h"

#define DS_HTABLE_MIN_CAPACITY 16 // Must be a power of 2

Expand Down Expand Up @@ -153,7 +152,7 @@ typedef struct _ds_htable_t {
} ds_htable_t;

ds_htable_t *ds_htable();
ds_vector_t *ds_htable_values_to_vector(ds_htable_t *table);
zval *ds_htable_values(ds_htable_t *table);

void ds_htable_ensure_capacity(ds_htable_t *table, uint32_t capacity);

Expand Down
4 changes: 2 additions & 2 deletions src/ds/ds_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void ds_map_to_array(ds_map_t *map, zval *return_value)
ds_htable_to_array(map->table, return_value);
}

ds_vector_t *ds_map_values_to_vector(ds_map_t *map)
zval *ds_map_values(ds_map_t *map)
{
return ds_htable_values_to_vector(map->table);
return ds_htable_values(map->table);
}

ds_map_t *ds_map_slice(ds_map_t *map, zend_long index, zend_long length)
Expand Down
3 changes: 1 addition & 2 deletions src/ds/ds_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "../common.h"
#include "ds_htable.h"
#include "ds_vector.h"
#include "ds_pair.h"

typedef struct _ds_map_t {
Expand Down Expand Up @@ -38,7 +37,7 @@ void ds_map_put_all(ds_map_t *map, zval *values);

ds_map_t *ds_map_slice(ds_map_t *map, zend_long index, zend_long length);

ds_vector_t *ds_map_values_to_vector(ds_map_t *map);
zval *ds_map_values(ds_map_t *map);

ds_map_t *ds_map_map(ds_map_t *map, FCI_PARAMS);
ds_map_t *ds_map_filter(ds_map_t *map);
Expand Down
1 change: 0 additions & 1 deletion src/ds/ds_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ ds_set_t *ds_set_xor(ds_set_t *set, ds_set_t *other)
void ds_set_assign_xor(ds_set_t *set, ds_set_t *other)
{
zval *value;
ds_set_t *result = ds_set();

DS_SET_FOREACH(set, value) {
if (_set_contains(other, value)) {
Expand Down
14 changes: 7 additions & 7 deletions src/php/classes/php_collection_ce.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

extern zend_class_entry *collection_ce;

#define PHP_DS_COLLECTION_INTERFACE_ME(cls, name) \
#define PHP_DS_COLLECTION_ME(cls, name) \
PHP_ME(cls, name, arginfo_Collection_##name, ZEND_ACC_PUBLIC)

#define PHP_DS_COLLECTION_ME_LIST(cls) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, clear) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, copy) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, count) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, isEmpty) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, jsonSerialize) \
PHP_DS_COLLECTION_INTERFACE_ME(cls, toArray)
PHP_DS_COLLECTION_ME(cls, clear) \
PHP_DS_COLLECTION_ME(cls, copy) \
PHP_DS_COLLECTION_ME(cls, count) \
PHP_DS_COLLECTION_ME(cls, isEmpty) \
PHP_DS_COLLECTION_ME(cls, jsonSerialize) \
PHP_DS_COLLECTION_ME(cls, toArray)

ARGINFO_NONE_RETURN_DS( Collection_copy, Collection);
ARGINFO_NONE( Collection_clear);
Expand Down
2 changes: 1 addition & 1 deletion src/php/classes/php_deque_ce.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void php_ds_register_deque()

zend_function_entry methods[] = {
PHP_DS_COLLECTION_ME_LIST(Deque)
SEQUENCE_ME_LIST(Deque)
PHP_DS_SEQUENCE_ME_LIST(Deque)
PHP_FE_END
};

Expand Down
Loading

0 comments on commit 31ad1f7

Please sign in to comment.