Skip to content

Commit 723841d

Browse files
committed
Minor refactoring
1 parent f691385 commit 723841d

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/cloudsync.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SQLITE_EXTENSION_INIT1
7474
#define CLOUDSYNC_PAYLOAD_APPLY_CALLBACK_KEY "cloudsync_payload_apply_callback"
7575

7676
#ifndef MAX
77-
#define MAX(a, b) (((a)>(b))?(a):(b))
77+
#define MAX(a, b) (((a)>(b))?(a):(b))
7878
#endif
7979

8080
#define DEBUG_SQLITE_ERROR(_rc, _fn, _db) do {if (_rc != SQLITE_OK) printf("Error in %s: %s\n", _fn, sqlite3_errmsg(_db));} while (0)
@@ -170,15 +170,17 @@ struct cloudsync_context {
170170
int schema_version;
171171
uint64_t schema_hash;
172172

173-
// set at the start of each transaction on the first invocation and re-set on transaction commit or rollback
173+
// set at the start of each transaction on the first invocation and
174+
// re-set on transaction commit or rollback
174175
sqlite3_int64 db_version;
175-
// the version that the db will be set to at the end of the transaction if that transaction were to commit at the time this value is checked
176+
// the version that the db will be set to at the end of the transaction
177+
// if that transaction were to commit at the time this value is checked
176178
sqlite3_int64 pending_db_version;
177179
// used to set an order inside each transaction
178180
int seq;
179181

180-
// augmented tables are stored in-memory so we do not need to retrieve information about col names and cid from the disk each time
181-
// a write statement is performed
182+
// augmented tables are stored in-memory so we do not need to retrieve information about col names and cid
183+
// from the disk each time a write statement is performed
182184
// we do also not need to use an hash map here because for few tables the direct in-memory comparison with table name is faster
183185
cloudsync_table_context **tables;
184186
int tables_count;
@@ -1309,7 +1311,7 @@ int cloudsync_merge_insert (sqlite3_vtab *vtab, int argc, sqlite3_value **argv,
13091311
// perform different logic for each different table algorithm
13101312
if (table->algo == table_algo_crdt_gos) return cloudsync_merge_insert_gos(vtab, data, table, insert_pk, insert_pk_len, insert_name, insert_value, insert_col_version, insert_db_version, insert_site_id, insert_site_id_len, insert_seq, rowid);
13111313

1312-
// TODO: handle DWS and AWS algorithms
1314+
// Handle DWS and AWS algorithms here
13131315
// Delete-Wins Set (DWS): table_algo_crdt_dws
13141316
// Add-Wins Set (AWS): table_algo_crdt_aws
13151317

@@ -2345,7 +2347,7 @@ void cloudsync_pk_encode (sqlite3_context *context, int argc, sqlite3_value **ar
23452347
cloudsync_memory_free(buffer);
23462348
}
23472349

2348-
int pk_decode_set_result_callback (void *xdata, int index, int type, int64_t ival, double dval, char *pval) {
2350+
int cloudsync_pk_decode_set_result_callback (void *xdata, int index, int type, int64_t ival, double dval, char *pval) {
23492351
cloudsync_pk_decode_context *decode_context = (cloudsync_pk_decode_context *)xdata;
23502352
// decode_context->index is 1 based
23512353
// index is 0 based
@@ -2384,7 +2386,7 @@ void cloudsync_pk_decode (sqlite3_context *context, int argc, sqlite3_value **ar
23842386
int i = sqlite3_value_int(argv[1]);
23852387

23862388
cloudsync_pk_decode_context xdata = {.context = context, .index = i};
2387-
pk_decode_prikey((char *)pk, strlen(pk), pk_decode_set_result_callback, &xdata);
2389+
pk_decode_prikey((char *)pk, strlen(pk), cloudsync_pk_decode_set_result_callback, &xdata);
23882390
}
23892391

23902392
// MARK: -
@@ -2639,9 +2641,6 @@ int cloudsync_cleanup_internal (sqlite3_context *context, const char *table_name
26392641
return SQLITE_OK;
26402642
}
26412643

2642-
#define MAX_TABLES 1000
2643-
#define MAX_NAME_LENGTH 128
2644-
26452644
void cloudsync_cleanup_all (sqlite3_context *context) {
26462645
char *sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'cloudsync_%' AND name NOT LIKE '%_cloudsync';";
26472646

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "sqlite3.h"
1717
#endif
1818

19-
#define CLOUDSYNC_VERSION "0.7.1"
19+
#define CLOUDSYNC_VERSION "0.7.2"
2020
#define CLOUDSYNC_TOMBSTONE_VALUE "__[RIP]__"
2121
#define CLOUDSYNC_RLS_RESTRICTED_VALUE "__[RLS]__"
2222
#define CLOUDSYNC_DISABLE_ROWIDONLY_TABLES 1

0 commit comments

Comments
 (0)