store ObjectSchema as a pointer rather than a reference

This commit is contained in:
Ari Lazier 2016-01-04 16:04:01 -08:00
parent aa5e1bef7d
commit df901c636f
7 changed files with 24 additions and 33 deletions

View File

@ -21,7 +21,7 @@ JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pro
return JSValueMakeNumber(ctx, size);
}
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(RJSValidatedPositiveIndex(indexStr))));
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(RJSValidatedPositiveIndex(indexStr))));
}
catch (std::out_of_range &exp) {
// getters for nonexistent properties in JS should always return undefined
@ -103,7 +103,7 @@ JSValueRef ListPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObjec
return JSValueMakeUndefined(ctx);
}
size_t index = size - 1;
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
list->remove(index);
return obj;
}
@ -140,7 +140,7 @@ JSValueRef ListShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj
list->verify_in_tranaction();
return JSValueMakeUndefined(ctx);
}
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(0)));
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(0)));
list->remove(0);
return obj;
}
@ -168,7 +168,7 @@ JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb
std::vector<JSObjectRef> removedObjects(remove);
for (size_t i = 0; i < remove; i++) {
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema(), list->get(index)));
list->remove(index);
}
for (size_t i = 2; i < argumentCount; i++) {

View File

@ -23,7 +23,7 @@ JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef
}
return RJSObjectCreate(ctx, Object(results->get_realm(),
results->object_schema,
results->object_schema(),
results->get(RJSValidatedPositiveIndex(indexStr))));
}
catch (std::out_of_range &exp) {
@ -76,9 +76,9 @@ JSValueRef SortByProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef th
Results *results = RJSGetInternal<Results *>(thisObject);
RJSValidateArgumentRange(argumentCount, 1, 2);
std::string propName = RJSValidatedStringForValue(ctx, arguments[0]);
const Property *prop = results->object_schema.property_for_name(propName);
const Property *prop = results->object_schema().property_for_name(propName);
if (!prop) {
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->object_schema.name + "'");
throw std::runtime_error("Property '" + propName + "' does not exist on object type '" + results->object_schema().name + "'");
}
bool ascending = true;

View File

@ -25,9 +25,9 @@
namespace realm {
class List {
public:
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), object_schema(s), m_link_view(l) {}
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {}
const ObjectSchema &object_schema;
const ObjectSchema &object_schema() const { return *m_object_schema; }
SharedRealm realm() { return m_realm; }
size_t size();
@ -53,6 +53,7 @@ namespace realm {
private:
SharedRealm m_realm;
const ObjectSchema *m_object_schema;
LinkViewRef m_link_view;
};
}

View File

@ -308,19 +308,19 @@ namespace realm {
template<typename ValueType, typename ContextType>
void List::add(ContextType ctx, ValueType value)
{
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
add(NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
}
template<typename ValueType, typename ContextType>
void List::insert(ContextType ctx, ValueType value, size_t list_ndx)
{
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
insert(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
}
template<typename ValueType, typename ContextType>
void List::set(ContextType ctx, ValueType value, size_t list_ndx)
{
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema.name, false));
set(list_ndx, NativeAccessor<ValueType, ContextType>::to_object_index(ctx, m_realm, value, object_schema().name, false));
}
}

View File

@ -40,7 +40,7 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s)
, m_table(m_query.get_table().get())
, m_sort(std::move(s))
, m_mode(Mode::Query)
, object_schema(o)
, m_object_schema(&o)
{
}
@ -48,21 +48,10 @@ Results::Results(SharedRealm r, const ObjectSchema &o, Table& table)
: m_realm(std::move(r))
, m_table(&table)
, m_mode(Mode::Table)
, object_schema(o)
, m_object_schema(&o)
{
}
Results& Results::operator=(Results const& r)
{
m_realm = r.m_realm;
m_table = r.m_table;
m_sort = r.m_sort;
m_query = r.get_query();
m_mode = Mode::Query;
const_cast<ObjectSchema &>(object_schema) = r.object_schema;
return *this;
}
void Results::validate_read() const
{
if (m_realm)
@ -171,7 +160,7 @@ size_t Results::index_of(Row const& row)
throw DetatchedAccessorException{};
}
if (m_table && row.get_table() != m_table) {
throw IncorrectTableException(object_schema.name,
throw IncorrectTableException(m_object_schema->name,
ObjectStore::object_type_for_table_name(row.get_table()->get_name()),
"Attempting to get the index of a Row of the wrong type"
);
@ -326,12 +315,12 @@ TableView Results::get_tableview()
Results Results::sort(realm::SortOrder&& sort) const
{
return Results(m_realm, object_schema, get_query(), std::move(sort));
return Results(m_realm, object_schema(), get_query(), std::move(sort));
}
Results Results::filter(Query&& q) const
{
return Results(m_realm, object_schema, get_query().and_query(std::move(q)), get_sort());
return Results(m_realm, object_schema(), get_query().and_query(std::move(q)), get_sort());
}
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table)

View File

@ -53,13 +53,13 @@ public:
Results(Results const&) = default;
Results(Results&&) = default;
Results& operator=(Results&&) = default;
Results& operator=(Results const&);
Results& operator=(Results const&) = default;
// Get the Realm
SharedRealm get_realm() const { return m_realm; }
// Object schema describing the vendored object type
const ObjectSchema &object_schema;
const ObjectSchema &object_schema() const { return *m_object_schema; }
// Get a query which will match the same rows as is contained in this Results
// Returned query will not be valid if the current mode is Empty
@ -72,7 +72,7 @@ public:
TableView get_tableview();
// Get the object type which will be returned by get()
StringData get_object_type() const noexcept { return object_schema.name; }
StringData get_object_type() const noexcept { return object_schema().name; }
// Get the size of this results
// Can be either O(1) or O(N) depending on the state of things
@ -163,6 +163,7 @@ public:
private:
SharedRealm m_realm;
const ObjectSchema *m_object_schema;
Query m_query;
TableView m_table_view;
Table* m_table = nullptr;

View File

@ -229,7 +229,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
{"type", RJSTypeGet(realm::PropertyTypeArray)},
{"id", store_object(js_object)},
{"size", list->size()},
{"schema", serialize_object_schema(list->object_schema)}
{"schema", serialize_object_schema(list->object_schema())}
};
}
else if (JSValueIsObjectOfClass(m_context, value, RJSResultsClass())) {
@ -238,7 +238,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
{"type", RealmObjectTypesResults},
{"id", store_object(js_object)},
{"size", results->size()},
{"schema", serialize_object_schema(results->object_schema)}
{"schema", serialize_object_schema(results->object_schema())}
};
}
else if (RJSIsValueArray(m_context, value)) {