From 5a4d9a54a05efee6cb004b41207e53b6eadbd1a8 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Fri, 18 Dec 2015 21:51:23 +0530 Subject: [PATCH 382/398] lokdocview: Use an array to install properties This way we can directly reference any property by pointers to GParamSpec stored in a static array, rather than looking for property using property name. The former is a faster approach. This will come in handy for functions, such as, g_object_notify which needs to access properties to notify the object of any property change in a faster way. Change-Id: Ic4087bff3bdb63a3e8853d158c7af688e5e67811 Reviewed-on: https://gerrit.libreoffice.org/20797 Tested-by: Jenkins Reviewed-by: David Tardon Tested-by: David Tardon (cherry picked from commit 81f31f5151b54899ac5461c9c7c4021cdf31a9a6) Reviewed-on: https://gerrit.libreoffice.org/21272 Reviewed-by: Pranav Kant (cherry picked from commit 09c73ad5b1462161b855bf3d43a3d86a3ee28659) --- libreofficekit/source/gtk/lokdocview.cxx | 187 +++++++++++++++---------------- 1 file changed, 90 insertions(+), 97 deletions(-) diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 4d2842005f37..07e5f993b79b 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -206,10 +206,13 @@ enum PROP_DOC_WIDTH, PROP_DOC_HEIGHT, PROP_CAN_ZOOM_IN, - PROP_CAN_ZOOM_OUT + PROP_CAN_ZOOM_OUT, + + PROP_LAST }; static guint doc_view_signals[LAST_SIGNAL] = { 0 }; +static GParamSpec *properties[PROP_LAST] = { nullptr }; static void lok_doc_view_initable_iface_init (GInitableIface *iface); static void callbackWorker (int nType, const char* pPayload, void* pData); @@ -2046,15 +2049,14 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * * The absolute path of the LibreOffice install. */ - g_object_class_install_property (pGObjectClass, - PROP_LO_PATH, - g_param_spec_string("lopath", - "LO Path", - "LibreOffice Install Path", - nullptr, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS))); + properties[PROP_LO_PATH] = + g_param_spec_string("lopath", + "LO Path", + "LibreOffice Install Path", + nullptr, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:lopointer: @@ -2062,28 +2064,26 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * A LibreOfficeKit* in case lok_init() is already called * previously. */ - g_object_class_install_property (pGObjectClass, - PROP_LO_POINTER, - g_param_spec_pointer("lopointer", - "LO Pointer", - "A LibreOfficeKit* from lok_init()", - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS))); + properties[PROP_LO_POINTER] = + g_param_spec_pointer("lopointer", + "LO Pointer", + "A LibreOfficeKit* from lok_init()", + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:docpath: * * The path of the document that is currently being viewed. */ - g_object_class_install_property (pGObjectClass, - PROP_DOC_PATH, - g_param_spec_string("docpath", - "Document Path", - "The URI of the document to open", - nullptr, - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_DOC_PATH] = + g_param_spec_string("docpath", + "Document Path", + "The URI of the document to open", + nullptr, + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:docpointer: @@ -2091,27 +2091,25 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * A LibreOfficeKitDocument* in case documentLoad() is already called * previously. */ - g_object_class_install_property (pGObjectClass, - PROP_DOC_POINTER, - g_param_spec_pointer("docpointer", - "Document Pointer", - "A LibreOfficeKitDocument* from documentLoad()", - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_DOC_POINTER] = + g_param_spec_pointer("docpointer", + "Document Pointer", + "A LibreOfficeKitDocument* from documentLoad()", + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:editable: * * Whether the document loaded inside of #LOKDocView is editable or not. */ - g_object_class_install_property (pGObjectClass, - PROP_EDITABLE, - g_param_spec_boolean("editable", - "Editable", - "Whether the content is in edit mode or not", - FALSE, - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_EDITABLE] = + g_param_spec_boolean("editable", + "Editable", + "Whether the content is in edit mode or not", + FALSE, + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:load-progress: @@ -2121,14 +2119,13 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * very accurate progress indicator, and its value might reset it couple of * times to 0 and start again. You should not rely on its numbers. */ - g_object_class_install_property (pGObjectClass, - PROP_LOAD_PROGRESS, - g_param_spec_double("load-progress", - "Estimated Load Progress", - "Shows the progress of the document load operation", - 0.0, 1.0, 0.0, - static_cast(G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_LOAD_PROGRESS] = + g_param_spec_double("load-progress", + "Estimated Load Progress", + "Shows the progress of the document load operation", + 0.0, 1.0, 0.0, + static_cast(G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:zoom-level: @@ -2136,14 +2133,13 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * The current zoom level of the document loaded inside #LOKDocView. The * default value is 1.0. */ - g_object_class_install_property (pGObjectClass, - PROP_ZOOM, - g_param_spec_float("zoom-level", - "Zoom Level", - "The current zoom level of the content", - 0, 5.0, 1.0, - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_ZOOM] = + g_param_spec_float("zoom-level", + "Zoom Level", + "The current zoom level of the content", + 0, 5.0, 1.0, + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:is-loading: @@ -2151,70 +2147,67 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) * Whether the requested document is being loaded or not. %TRUE if it is * being loaded, otherwise %FALSE. */ - g_object_class_install_property (pGObjectClass, - PROP_IS_LOADING, - g_param_spec_boolean("is-loading", - "Is Loading", - "Whether the view is loading a document", - FALSE, - static_cast(G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_IS_LOADING] = + g_param_spec_boolean("is-loading", + "Is Loading", + "Whether the view is loading a document", + FALSE, + static_cast(G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:doc-width: * * The width of the currently loaded document in #LOKDocView in twips. */ - g_object_class_install_property (pGObjectClass, - PROP_DOC_WIDTH, - g_param_spec_long("doc-width", - "Document Width", - "Width of the document in twips", - 0, G_MAXLONG, 0, - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_DOC_WIDTH] = + g_param_spec_long("doc-width", + "Document Width", + "Width of the document in twips", + 0, G_MAXLONG, 0, + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:doc-height: * * The height of the currently loaded document in #LOKDocView in twips. */ - g_object_class_install_property (pGObjectClass, - PROP_DOC_HEIGHT, - g_param_spec_long("doc-height", - "Document Height", - "Height of the document in twips", - 0, G_MAXLONG, 0, - static_cast(G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS))); + properties[PROP_DOC_HEIGHT] = + g_param_spec_long("doc-height", + "Document Height", + "Height of the document in twips", + 0, G_MAXLONG, 0, + static_cast(G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); /** * LOKDocView:can-zoom-in: * * It tells whether the view can further be zoomed in or not. */ - g_object_class_install_property (pGObjectClass, - PROP_CAN_ZOOM_IN, - g_param_spec_boolean("can-zoom-in", - "Can Zoom In", - "Whether the view can be zoomed in further", - TRUE, - static_cast(G_PARAM_READABLE - | G_PARAM_STATIC_STRINGS))); + properties[PROP_CAN_ZOOM_IN] = + g_param_spec_boolean("can-zoom-in", + "Can Zoom In", + "Whether the view can be zoomed in further", + TRUE, + static_cast(G_PARAM_READABLE + | G_PARAM_STATIC_STRINGS)); /** * LOKDocView:can-zoom-out: * * It tells whether the view can further be zoomed out or not. */ - g_object_class_install_property (pGObjectClass, - PROP_CAN_ZOOM_OUT, - g_param_spec_boolean("can-zoom-out", - "Can Zoom Out", - "Whether the view can be zoomed out further", - TRUE, - static_cast(G_PARAM_READABLE - | G_PARAM_STATIC_STRINGS))); + properties[PROP_CAN_ZOOM_OUT] = + g_param_spec_boolean("can-zoom-out", + "Can Zoom Out", + "Whether the view can be zoomed out further", + TRUE, + static_cast(G_PARAM_READABLE + | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties(pGObjectClass, PROP_LAST, properties); /** * LOKDocView::load-changed: -- 2.12.0