Permalink
Browse files

Opitimizing [json-encode]

  • Loading branch information...
1 parent 1537989 commit f260753585008611cb00588fbd66757dde65c2b0 @residuum committed Apr 12, 2012
Showing with 37 additions and 28 deletions.
  1. +6 −0 Changelog.txt
  2. +8 −0 debian/changelog
  3. +13 −19 json-encode.c
  4. +1 −1 purest_json-meta.pd
  5. +2 −1 purest_json.h
  6. +7 −7 rest-json.c
View
@@ -1,4 +1,10 @@
Changelog
+
+0.7:
+- Cookie authentication, useful for CouchDB login
+- [rest-json] has a third outlet
+- Refactoring
+
0.6:
- Lots of bugfixes
View
@@ -1,3 +1,11 @@
+pd-purest-json (0.7) UNRELEASED; urgency=low
+
+ * Cookie authentication, useful for CouchDB login
+ * [rest-json] has a third outlet
+ * Refactoring
+
+ -- Thomas Mayer <thomas@residuum.org> Thu, 12 Apr 2012 20:17:20 +0200
+
pd-purest-json (0.6) UNRELEASED; urgency=low
* Lots of bugfixes.
View
@@ -10,7 +10,7 @@ void json_encode_free_memory(t_json_encode *x) {
t_key_value_pair *data_to_free;
t_key_value_pair *next_data;
- data_to_free = x->data;
+ data_to_free = x->first_data;
while(data_to_free != NULL) {
next_data = data_to_free->next;
freebytes(data_to_free->key, MAXPDSTRING);
@@ -20,7 +20,8 @@ void json_encode_free_memory(t_json_encode *x) {
}
x->data_count = 0;
- x->data = NULL;
+ x->first_data = NULL;
+ x->last_data = NULL;
}
static json_object *create_object(char *value) {
@@ -81,7 +82,7 @@ void json_encode_bang(t_json_encode *x) {
json_object *array_members[x->data_count];
if (x->data_count > 0) {
- data_member = x->data;
+ data_member = x->first_data;
for (i = 0; i < x->data_count; i++) {
already_added = 0;
/* Is it an array member? */
@@ -128,7 +129,6 @@ void json_encode_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom
char *value;
char temp_value[MAXPDSTRING];
t_key_value_pair *created_data = NULL;
- t_key_value_pair *previous_data = NULL;
int i;
(void) selector;
@@ -154,15 +154,12 @@ void json_encode_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom
created_data->value = value;
created_data->next = NULL;
created_data->is_array = 0;
- if (x->data == NULL) {
- x->data = created_data;
+ if (x->first_data == NULL) {
+ x->first_data = created_data;
} else {
- previous_data = x->data;
- while (previous_data->next) {
- previous_data = previous_data->next;
- }
- previous_data->next = created_data;
+ x->last_data->next = created_data;
}
+ x->last_data = created_data;
x->data_count++;
}
@@ -173,7 +170,6 @@ void json_encode_array_add(t_json_encode *x, t_symbol *selector, int argcount, t
char *value;
char temp_value[MAXPDSTRING];
t_key_value_pair *created_data = NULL;
- t_key_value_pair *previous_data = NULL;
int i;
(void) selector;
@@ -199,15 +195,13 @@ void json_encode_array_add(t_json_encode *x, t_symbol *selector, int argcount, t
created_data->value = value;
created_data->next = NULL;
created_data->is_array = 1;
- if (x->data == NULL) {
- x->data = created_data;
+ if (x->first_data == NULL) {
+ x->first_data = created_data;
} else {
- previous_data = x->data;
- while (previous_data->next) {
- previous_data = previous_data->next;
- }
- previous_data->next = created_data;
+ x->last_data->next = created_data;
}
+ x->last_data = created_data;
+
x->data_count++;
}
}
View
@@ -1,6 +1,6 @@
#N canvas 15 49 200 200 10;
#N canvas 25 49 420 300 META 1;
-#X text 10 10 VERSION 0.6;
+#X text 10 10 VERSION 0.7;
#X text 10 25 AUTHOR thomas@residuum.org;
#X text 13 41 NAME purest_json;
#X restore 10 10 pd META;
View
@@ -48,7 +48,8 @@ typedef struct rest {
/* [json-encode] */
typedef struct json_encode {
t_object x_ob;
- t_key_value_pair *data;
+ t_key_value_pair *first_data;
+ t_key_value_pair *last_data;
int data_count;
} t_json_encode;
View
@@ -226,6 +226,13 @@ static void get_auth_token(t_rest *x) {
static void set_url_parameters(t_rest *x, int argcount, t_atom *argvec) {
switch (argcount) {
+ case 0:
+ memset(x->base_url, 0x00, MAXPDSTRING);
+ memset(x->login_path, 0x00, MAXPDSTRING);
+ memset(x->username, 0x00, MAXPDSTRING);
+ memset(x->password, 0x00, MAXPDSTRING);
+ memset(x->auth_token, 0x00, MAXPDSTRING);
+ break;
case 1:
if (argvec[0].a_type != A_SYMBOL) {
error("Base URL cannot be set.");
@@ -261,13 +268,6 @@ static void set_url_parameters(t_rest *x, int argcount, t_atom *argvec) {
}
get_auth_token(x);
break;
- case 0:
- memset(x->base_url, 0x00, MAXPDSTRING);
- memset(x->login_path, 0x00, MAXPDSTRING);
- memset(x->username, 0x00, MAXPDSTRING);
- memset(x->password, 0x00, MAXPDSTRING);
- memset(x->auth_token, 0x00, MAXPDSTRING);
- break;
default:
error("Wrong number of parameters.");
break;

0 comments on commit f260753

Please sign in to comment.